Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int activepiezzopin = 11;
- const int buttons = A0;
- int notes [] = {261, 392, 440, 349};
- void setup()
- {
- pinMode (activepiezzopin, OUTPUT);
- pinMode (buttons, INPUT);
- Serial.begin (9600);
- }
- void loop()
- {
- int buttonval = analogRead (A0);
- Serial.println (buttonval);
- if (buttonval > 0 && buttonval < 100)
- {
- tone (activepiezzopin, notes[0], 200);
- }
- else if (buttonval > 500 && buttonval < 600)
- {
- tone (activepiezzopin, notes[1], 200);
- }
- else if (buttonval > 995 && buttonval < 1010)
- {
- tone (activepiezzopin, notes[2], 200);
- }
- else if (buttonval == 1023)
- {
- tone (activepiezzopin, notes[3], 200);
- }
- else
- {
- noTone (activepiezzopin);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement