Hey, I'm new to the whole maker thing and I'm actually taking a class at my college on arduino programming. I'm having a little trouble with one of the thing's I'm working on where we had to compose a song on our arduino leonardo's with 321 make boards. I got through most of it just fine (assigning a button press to play a 15 second song loop) but I'm having trouble with the second part. I'm supposed to map a colour to each tone that's played so each time a note is played it makes it's own little light show.I tried using an if statement with something to the effect of
if (tone(buzzerPin, NOTE_F4, 500)){
digitalWrite (RGBRedpin, HIGH);
}
I've cut out most of the song so you guys don't have to sift through as much. I appreciate any help that I can get.
#include "pitches.h";
int buzzerPin = 5 ; //The buzzerPin is connected to pin 5 of the Arduino.
int button1Pin = 2; //The SW1 button is connect to pin 2 of the Arduino.
int RGBRedPin = 9; //The red RGB LED is connected pin 9 of the Arduino.
int RGBGreenPin = 10; //The green RGB LED is connected pin 10 of the Arduino.
int RGBBluePin = 11; //The blue RGB LED is connected pin 11 of the Arduino.
int Color;
void setup() { //The Setup function runs once.
pinMode(buzzerPin, OUTPUT); //Setup red LED pin as an output pin.
pinMode(button1Pin, INPUT); //Setup button1 pin as an input pin.
pinMode(RGBRedPin, OUTPUT); //Setup red RGB LED pin as an output pin.
pinMode(RGBGreenPin, OUTPUT); //Setup green RGB LED pin as an output pin.
pinMode(RGBBluePin, OUTPUT); //Setup blue RGB LED pin as an output pin.
Serial.begin(9600);
}
void loop() { //The loop function runs forever.
if (digitalRead(button1Pin) == LOW) { //Check to see if button1 is pressed.
//Opening repeating thing
tone(buzzerPin, NOTE_D4, 500);
delay(204);
tone(buzzerPin, NOTE_D4, 500);
delay(204);
tone(buzzerPin, NOTE_D5, 500);
delay(204);
tone(buzzerPin, NOTE_A4, 500);
delay(204);
}
}