Skip to content

Instantly share code, notes, and snippets.

@Bryniac
Created January 10, 2021 09:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bryniac/0c03831108e087f7aff9148b11be803a to your computer and use it in GitHub Desktop.
Save Bryniac/0c03831108e087f7aff9148b11be803a to your computer and use it in GitHub Desktop.
I have been learning Arduino for a few days so I tried modifying an existing project. This gist was based on https://gist.github.com/nicksort/4736535
const int d4s = 311;
const int e4 = 330;
const int f4s = 370;
const int g4s = 415;
const int a4 = 440;
const int b4 = 494;
const int c5s = 523;
const int buzzerPin = 4;
const int ledPinB = 12;
const int ledPinR = 13;
int counter =0;
void setup() {
// put your setup code here, to run once:
pinMode(buzzerPin, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinR, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
firstSection();
secondSection();
firstSection();
lastSection();
}
void beep( int note, int duration) {
//Play tone on buzzerPin
tone(buzzerPin, note, duration);
//Play different LED depending on value of 'counter'
if(counter % 2 == 0)
{
digitalWrite(ledPinB, HIGH);
delay(duration);
digitalWrite(ledPinB, LOW);
}else
{
digitalWrite(ledPinR, HIGH);
delay(duration);
digitalWrite(ledPinR, LOW);
}
//Stop tone on buzzerPin
noTone(buzzerPin);
delay(50);
//Increment counter
counter++;
}
void firstSection (){
beep(d4s, 500);
beep(f4s, 250);
beep(g4s, 250);
beep(a4, 1000);
beep(g4s,500);
beep(f4s, 1000);
delay(250);
}
void secondSection (){
beep(d4s, 250);
beep(f4s, 250);
beep(g4s, 250);
beep(a4, 1000);
beep(b4,500);
beep(a4, 250);
beep(b4,500);
beep(c5s, 500);
delay(250);
}
void lastSection (){
beep(f4s, 250);
beep(c5s, 250);
beep(b4, 250);
delay(250);
beep(f4s, 250);
beep(c5s, 250);
beep(b4, 250);
delay(250);
beep(e4, 500);
beep(e4, 250);
delay(250);
beep(f4s, 250);
beep(f4s, 1000);
delay(250);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment