Homework

จงออกแบบ Metronome ที่สามารถปรับค่า BPM ได้ตั้งแต่ 40 -100 BPM โดยใช้สัญญาณ clock ที่ความถี่ 100 Hz

-hint code-

const int input = 12; // This is where the input is fed.
int pulse = 0; // Variable for saving pulses count.
int var = 0;

void setup(){
  pinMode(input, INPUT);
 
  Serial.begin(9600);
}

void loop(){ 
  if(digitalRead(input) > var)
  {
    var = 1;
    pulse++;   
    Serial.println(pulse);
    //Serial.print(F(" pulse"));

    // Put an "s" if the amount of pulses is greater than 1.
    if(pulse > 1) {Serial.print(F("s"));}
   
   // Serial.println(F(" detected."));
  }
 
  if(digitalRead(input) == 0) {var = 0;}
 
}

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University