Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int speakerPin = 9;
- int length = 1;
- char notes[] = "c";
- int beats[] = {1};
- int tempo = 125;
- void playTone(int tone, int duration)
- {
- for (long i = 0; 1 < duration * 1000L; i += tone * 2)
- {
- digitalWrite(speakerPin, HIGH);
- delayMicroseconds(tone);
- digitalWrite(speakerPin, LOW);
- delayMicroseconds(tone);
- }
- }
- void playNote(char note, int duration)
- {
- char names[] = {'c'};
- int tones[] = {1915};
- for (int i = 0; i < 8; i++)
- {
- if (names[i] == note)
- {
- playTone(tones[i], duration);
- }
- }
- }
- void setup()
- {
- pinMode(13, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(11, OUTPUT);
- pinMode(10, OUTPUT);
- pinMode(speakerPin, OUTPUT);
- }
- void loop() {
- for (int i = 0; i < length; i++)
- {
- if (notes[i] == 'c')
- {
- playNote(notes[i], beats[i] * tempo);
- delay(beats[i] * tempo);
- delay(tempo / 2);
- digitalWrite(13, HIGH);
- delay(50);
- digitalWrite(12, HIGH);
- delay(50);
- digitalWrite(11, HIGH);
- delay(50);
- digitalWrite(10, HIGH);
- delay(50);
- digitalWrite(13, LOW);
- delay(50);
- digitalWrite(12, LOW);
- delay(50);
- digitalWrite(11, LOW);
- delay(50);
- digitalWrite(10, LOW);
- delay(50);
- }
- }
- }
Add Comment
Please, Sign In to add comment