استخدام الطنان مع الأزرار القابلة للضغط

المشروع السابع

عن المشروع

في نهاية هذه السلسلة، احب ان اقدم لكم هذا المشروع المميز! انشاء بيانو بدائية من خلال المتحكم الدقيق (:

فيديو المشروع

خريطة الربط

تم الإنشاء بواسطة

fritzing.org

الشيفرة البرمجية

int pushbutton1 = 8;

int pushbutton2 = 9;

int pushbutton3 = 10;

int pushbutton4 = 11;

int pushbutton5 = 12;

int buzzer =3;






void setup (){


  pinMode(pushbutton1,INPUT);

  pinMode(pushbutton2,INPUT);

  pinMode(pushbutton3,INPUT);

  pinMode(pushbutton4,INPUT);

  pinMode(pushbutton5,INPUT);

  pinMode(buzzer,OUTPUT);

Serial.begin(9600);

}


void loop (){



  

int pushbutton1_readings= digitalRead(pushbutton1);

int pushbutton2_readings= digitalRead(pushbutton2);

int pushbutton3_readings= digitalRead(pushbutton3);

int pushbutton4_readings= digitalRead(pushbutton4);

int pushbutton5_readings= digitalRead(pushbutton5);


int total =  pushbutton1_readings + 2*pushbutton2_readings + 3*pushbutton3_readings + 4*pushbutton4_readings + 5*pushbutton5_readings;

Serial.println(total);

if ( total >=1 ){


  tone(buzzer,total*150);

}

if (total == 0){

  noTone(buzzer);

}

}



شريط التنقل بين المشاريع