top of page
Check back soon
Once posts are published, you’ll see them here.

Arduino button music

  • Dec 2, 2016
  • 1 min read

const int buttonPin2 = 2; // the number of the pushbutton pin const int buttonPin3 = 3; const int buttonPin4 = 4; const int buttonPin5 = 5; const int buttonPin6 = 6; //const int buttonPin7 = 7; //const int buttonPin8 = 8;

int speakerPin = 9; int tone1 = 1915; int tone2 = 1700; int tone3 = 1519; int tone4 = 1432; int tone5 = 1275; //int tone6 = 1136; //int tone7 = 1014;

// variables will change: //int buttonState = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: //pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(speakerPin, OUTPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT);

pinMode(buttonPin4, INPUT);

pinMode(buttonPin5, INPUT);

pinMode(buttonPin6, INPUT); }

void loop() { // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (digitalRead(buttonPin2) == HIGH) {//DO digitalWrite(speakerPin, HIGH); delayMicroseconds(tone1); } else { digitalWrite(speakerPin, LOW); delayMicroseconds(tone1); }

if (digitalRead(buttonPin3) == HIGH) {//RE digitalWrite(speakerPin, HIGH); delayMicroseconds(tone2); } else { digitalWrite(speakerPin, LOW); delayMicroseconds(tone2); }

if (digitalRead(buttonPin4) == HIGH) {//ME digitalWrite(speakerPin, HIGH); delayMicroseconds(tone3); } else { digitalWrite(speakerPin, LOW); delayMicroseconds(tone3); }

if (digitalRead(buttonPin5) == HIGH) {//FA digitalWrite(speakerPin, HIGH); delayMicroseconds(tone4); } else { digitalWrite(speakerPin, LOW); delayMicroseconds(tone4); }

if (digitalRead(buttonPin6) == HIGH) {//SO digitalWrite(speakerPin, HIGH); delayMicroseconds(tone5); } else { digitalWrite(speakerPin, LOW); delayMicroseconds(tone5); }

}


 
 
 

Comments


join us

 for the 

PARTY

Recipe Exchange @ 9pm!

start

 with 

Ubuntu

ubuntu   12.04

Linux 桌面系統
心得與筆記
  • 課程:Linux桌面系統

  • 系級:資管二甲

  • 姓名:蘇亭云

  • 學號:403401263.

Read More About me
Tag Cloud
Follow Me
  • Facebook - White Circle
  • Twitter - White Circle
  • Google+ - White Circle
  • YouTube - White Circle
  • Instagram - White Circle

© 2023 by My Weight Lost Journey. Proudly Created with Wix.com

bottom of page