Created
January 12, 2015 00:41
-
-
Save fernandozamoraj/190a81fafc1d7984ede5 to your computer and use it in GitHub Desktop.
Beat with Buzzer - Arduino Sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copied my first sketch from the blink sketch and modified it 11Jan2015- Fernando | |
Blink | |
Turns on an LED on for one second, then off for one second, repeatedly. | |
Most Arduinos have an on-board LED you can control. On the Uno and | |
Leonardo, it is attached to digital pin 13. If you're unsure what | |
pin the on-board LED is connected to on your Arduino model, check | |
the documentation at http://arduino.cc | |
This example code is in the public domain. | |
modified 8 May 2014 | |
by Scott Fitzgerald | |
modified 11 Jan 2015 | |
by Fernando Zamora | |
If you attached a LED and a Buzzer in the circuit it plays a beat | |
I added a 220Ohm resistor and buzzer in paralle with the 220ohm resitos and LED | |
*/ | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin 13 as an output. | |
pinMode(13, OUTPUT); | |
pinMode(7, INPUT); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
int on = digitalRead(7); | |
if(on != HIGH){ | |
delay(500); | |
return; | |
} | |
multiStep(3, 13, 500, 10 ); | |
delay(500); | |
multiStep(3, 13, 500, 10 ); | |
delay(500); | |
/* | |
cricketBeat(10, 3); | |
cricketBeat(10, 1); | |
cricketBeat(10, 3); | |
cricketBeat(10, 3); | |
cricketBeat(10, 1); | |
cricketBeat(10, 3); | |
cricketBeat(10, 1); | |
cricketBeat(10, 3); | |
cricketBeat(10, 1); | |
cricketBeat(100, 2); | |
cricketBeat(500, 2); | |
cricketBeat(1000, 2); | |
*/ | |
} | |
void cricketBeat(int waitDelay, int loops){ | |
for(int i =0 ; i < loops; i++){ | |
multiStep(13, 13, waitDelay, 10 ); | |
delay(100); | |
} | |
delay(1000); | |
} | |
void master1(){ | |
beat2(); | |
beat1(); | |
beat1(); | |
beat1(); | |
delay(1000); | |
} | |
void beat2(){ | |
multiStep(3, 13, 300, 300); | |
} | |
void beat1(){ | |
longBeat(3, 6); | |
fastDrumSequence(); | |
} | |
void longBeat(int low, int high){ | |
for(int i = high; i > low; i--){ | |
multiStep(i, 13, 10, 30 ); | |
delay(50); | |
} | |
} | |
void fastDrumSequence(){ | |
delay(100); | |
multiStep(11, 13, 30, 30 ); | |
delay(100); | |
multiStep(11, 13, 30, 30 ); | |
delay(100); | |
multiStep(11, 13, 30, 30 ); | |
delay(1000); | |
} | |
void multiStep(int beats, int ledPin, int firstDelay, int secondDelay){ | |
for(int i = 0; i < beats; i++){ | |
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(firstDelay); // wait for a second | |
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW | |
delay(secondDelay); // wait for a second | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment