const int BLED=9; // Blue LED Cathode on Pin 9
const int GLED=10; // Green LED Cathode on Pin 10
const int RLED=11; // Red LED Cathode on Pin 11
const int BUTTON=2; // The Button1 is connected to pin 2
int buttonPin1 = 7; //Start button
int buttonPin2 = 8; //Stop button
boolean lastButton = LOW; //Last Button State
boolean currentButton = LOW; //Current Button State
boolean lastButtonone = LOW; //Last Button State
boolean currentButtonone = LOW; //Current Button State
boolean lastButtontwo = LOW; //Last Button State
boolean currentButtontwo = LOW; //Current Button State
int ledMode = 0; //cycle between LED states
int play = 0; //cycle between LED states
#include "pitches.h" //Header file with pitch definitions
#define REST 0
int SpeakerState = LOW;
const int SPEAKER=5; //Speaker Pin
unsigned long previousMillis = 0;
//Red Note Array
int tempor = 85;
int rnotes[] = {
NOTE_E5, 8, NOTE_D5, 8, NOTE_FS4, 4, NOTE_GS4, 4,
NOTE_CS5, 8, NOTE_B4, 8, NOTE_D4, 4, NOTE_E4, 4,
NOTE_B4, 8, NOTE_A4, 8, NOTE_CS4, 4, NOTE_E4, 4,
NOTE_A4, 2,
};
int notesr = sizeof(rnotes) / sizeof(rnotes[0]) / 2;
int wholenoter = (60000 * 4) / tempor;
int dividerr = 0, noteDurationr = 0;
//End Red Note Array
//Green Note Array
int tempog = 132;
int gnotes[] = {
NOTE_C4,-8, NOTE_E4,16, NOTE_G4,8, NOTE_C5,8, NOTE_E5,8, NOTE_D5,8, NOTE_C5,8, NOTE_A4,8,
NOTE_FS4,8, NOTE_G4,8, REST,4, REST,2,
NOTE_C4,-8, NOTE_E4,16, NOTE_G4,8, NOTE_C5,8, NOTE_E5,8, NOTE_D5,8, NOTE_C5,8, NOTE_A4,8,
NOTE_G4,-2, NOTE_A4,8, NOTE_DS4,1,
NOTE_A4,8,
NOTE_E4,8, NOTE_C4,8, REST,4, REST,2,
NOTE_C4,-8, NOTE_E4,16, NOTE_G4,8, NOTE_C5,8, NOTE_E5,8, NOTE_D5,8, NOTE_C5,8, NOTE_A4,8,
NOTE_FS4,8, NOTE_G4,8, REST,4, REST,4, REST,8, NOTE_G4,8,
NOTE_D5,4, NOTE_D5,4, NOTE_B4,8, NOTE_G4,8, REST,8, NOTE_G4,8,
NOTE_C5,4, NOTE_C5,4, NOTE_AS4,16, NOTE_C5,16, NOTE_AS4,16, NOTE_G4,16, NOTE_F4,8, NOTE_DS4,8,
NOTE_FS4,4, NOTE_FS4,4, NOTE_F4,16, NOTE_G4,16, NOTE_F4,16, NOTE_DS4,16, NOTE_C4,8, NOTE_G4,8,
NOTE_AS4,8, NOTE_C5,8, REST,4, REST,2,
};
int notesg = sizeof(gnotes) / sizeof(gnotes[0]) / 2;
int wholenoteg = (60000 * 4) / tempog;
int dividerg = 0, noteDurationg = 0;
//Blue Note Array
int tempob = 180;
int bnotes[] = {
NOTE_D5,-4, NOTE_A5,8, NOTE_FS5,8, NOTE_D5,8,
NOTE_E5,-4, NOTE_FS5,8, NOTE_G5,4,
NOTE_FS5,-4, NOTE_E5,8, NOTE_FS5,4,
NOTE_D5,-2,
NOTE_D5,-4, NOTE_A5,8, NOTE_FS5,8, NOTE_D5,8,
NOTE_E5,-4, NOTE_FS5,8, NOTE_G5,4,
NOTE_FS5,-1,
NOTE_D5,-4, NOTE_A5,8, NOTE_FS5,8, NOTE_D5,8,
NOTE_E5,-4, NOTE_FS5,8, NOTE_G5,4,
NOTE_FS5,-4, NOTE_E5,8, NOTE_FS5,4,
NOTE_D5,-2,
NOTE_D5,-4, NOTE_A5,8, NOTE_FS5,8, NOTE_D5,8,
NOTE_E5,-4, NOTE_FS5,8, NOTE_G5,4,
NOTE_FS5,-1,
};
int notesb = sizeof(bnotes) / sizeof(bnotes[0]) / 2;
int wholenoteb = (60000 * 4) / tempob;
int dividerb = 0, noteDurationb = 0;
//Purple Note Array
int tempop = 120;
int pnotes[] = {
NOTE_G4,8, NOTE_A4,8, NOTE_B4,4, NOTE_D5,4, NOTE_D5,4, NOTE_B4,4,
NOTE_C5,4, NOTE_C5,2, NOTE_G4,8, NOTE_A4,8,
NOTE_B4,4, NOTE_D5,4, NOTE_D5,4, NOTE_C5,4,
NOTE_B4,2, REST,8, NOTE_G4,8, NOTE_G4,8, NOTE_A4,8,
NOTE_B4,4, NOTE_D5,4, REST,8, NOTE_D5,8, NOTE_C5,8, NOTE_B4,8,
NOTE_G4,4, NOTE_C5,4, REST,8, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8,
NOTE_A4,4, NOTE_B4,4, REST,8, NOTE_B4,8, NOTE_A4,8, NOTE_G4,8,
NOTE_G4,2, REST,8, NOTE_G4,8, NOTE_G4,8, NOTE_A4,8,
NOTE_B4,4, NOTE_D5,4, REST,8, NOTE_D5,8, NOTE_C5,8, NOTE_B4,8,
NOTE_G4,4, NOTE_C5,4, REST,8, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8,
NOTE_A4,4, NOTE_B4,4, REST,8, NOTE_B4,8, NOTE_A4,8, NOTE_G4,8,
NOTE_G4,4, NOTE_F5,8, NOTE_D5,8, NOTE_E5,8, NOTE_C5,8, NOTE_D5,8, NOTE_B4,8,
NOTE_C5,8, NOTE_A4,8, NOTE_B4,8, NOTE_G4,8, NOTE_A4,8, NOTE_G4,8, NOTE_E4,8, NOTE_G4,8,
NOTE_G4,4, NOTE_F5,8, NOTE_D5,8, NOTE_E5,8, NOTE_C5,8, NOTE_D5,8, NOTE_B4,8,
NOTE_C5,8, NOTE_A4,8, NOTE_B4,8, NOTE_G4,8, NOTE_A4,8, NOTE_G4,8, NOTE_E4,8, NOTE_G4,8,
NOTE_G4,-2, REST,4
};
int notesp = sizeof(pnotes) / sizeof(pnotes[0]) / 2;
int wholenotep = (60000 * 4) / tempop;
int dividerp = 0, noteDurationp = 0;
//Teal Note Array
int tempot = 108;
int tnotes[] = {
NOTE_AS4,8, NOTE_AS4,8, NOTE_AS4,8,//1
NOTE_F5,2, NOTE_C6,2,
NOTE_AS5,8, NOTE_A5,8, NOTE_G5,8, NOTE_F6,2, NOTE_C6,4,
NOTE_AS5,8, NOTE_A5,8, NOTE_G5,8, NOTE_F6,2, NOTE_C6,4,
NOTE_AS5,8, NOTE_A5,8, NOTE_AS5,8, NOTE_G5,2, NOTE_C5,8, NOTE_C5,8, NOTE_C5,8,
NOTE_F5,2, NOTE_C6,2,
NOTE_AS5,8, NOTE_A5,8, NOTE_G5,8, NOTE_F6,2, NOTE_C6,4,
NOTE_AS5,8, NOTE_A5,8, NOTE_G5,8, NOTE_F6,2, NOTE_C6,4, //8
NOTE_AS5,8, NOTE_A5,8, NOTE_AS5,8, NOTE_G5,2, NOTE_C5,-8, NOTE_C5,16,
NOTE_D5,-4, NOTE_D5,8, NOTE_AS5,8, NOTE_A5,8, NOTE_G5,8, NOTE_F5,8,
NOTE_F5,8, NOTE_G5,8, NOTE_A5,8, NOTE_G5,4, NOTE_D5,8, NOTE_E5,4,NOTE_C5,-8, NOTE_C5,16,
NOTE_D5,-4, NOTE_D5,8, NOTE_AS5,8, NOTE_A5,8, NOTE_G5,8, NOTE_F5,8,
NOTE_C6,-8, NOTE_G5,16, NOTE_G5,2, REST,8, NOTE_C5,8,//13
NOTE_D5,-4, NOTE_D5,8, NOTE_AS5,8, NOTE_A5,8, NOTE_G5,8, NOTE_F5,8,
NOTE_F5,8, NOTE_G5,8, NOTE_A5,8, NOTE_G5,4, NOTE_D5,8, NOTE_E5,4,NOTE_C6,-8, NOTE_C6,16,
NOTE_F6,4, NOTE_DS6,8, NOTE_CS6,4, NOTE_C6,8, NOTE_AS5,4, NOTE_GS5,8, NOTE_G5,4, NOTE_F5,8,
NOTE_C6,1
};
int notest = sizeof(tnotes) / sizeof(tnotes[0]) / 2;
int wholenotet = (60000 * 4) / tempot;
int dividert = 0, noteDurationt = 0;
//Orange Note Array
int tempoo = 108;
int onotes[] = {
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,2, NOTE_C4,8, NOTE_D4,8,
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,-2,
NOTE_E4,2, NOTE_G4,4,
NOTE_D5,2, NOTE_C5,4,
NOTE_G4,2, NOTE_F4,8, NOTE_E4,8,
NOTE_D4,-2,
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,2, NOTE_C4,8, NOTE_D4,8,
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,-2,
NOTE_E4,2, NOTE_G4,4,
NOTE_D5,2, NOTE_C5,4,
NOTE_G4,2, NOTE_F4,8, NOTE_E4,8,
NOTE_F4,8, NOTE_E4,8, NOTE_C4,2,
NOTE_F4,2, NOTE_E4,8, NOTE_D4,8,
NOTE_E4,8, NOTE_D4,8, NOTE_A3,2,
NOTE_G4,2, NOTE_F4,8, NOTE_E4,8,
NOTE_F4,8, NOTE_E4,8, NOTE_C4,4, NOTE_F4,4,
NOTE_C5,-2,
};
int noteso = sizeof(onotes) / sizeof(onotes[0]) / 2;
int wholenoteo = (60000 * 4) / tempoo;
int dividero = 0, noteDurationo = 0;
//White Note Array
int tempow = 140;
int wnotes[] = {
NOTE_C4,4, NOTE_C4,8,
NOTE_D4,-4, NOTE_C4,-4, NOTE_F4,-4,
NOTE_E4,-2, NOTE_C4,4, NOTE_C4,8,
NOTE_D4,-4, NOTE_C4,-4, NOTE_G4,-4,
NOTE_F4,-2, NOTE_C4,4, NOTE_C4,8,
NOTE_C5,-4, NOTE_A4,-4, NOTE_F4,-4,
NOTE_E4,-4, NOTE_D4,-4, NOTE_AS4,4, NOTE_AS4,8,
NOTE_A4,-4, NOTE_F4,-4, NOTE_G4,-4,
NOTE_F4,-2,
};
int notesw = sizeof(wnotes) / sizeof(wnotes[0]) / 2;
int wholenotew = (60000 * 4) / tempow;
int dividerw = 0, noteDurationw = 0;
void setup()
{
pinMode (BLED, OUTPUT); // Set Blue LED as Output
pinMode (GLED, OUTPUT); // Set Green LED as Output
pinMode (RLED, OUTPUT); // Set Red LED as Output
pinMode (BUTTON, INPUT); // Set button as input (not required)
pinMode(buttonPin1, INPUT);
}
/*
* Debouncing Function
* Pass it the previous button state,
* and get back the current debounced button state.
*/
boolean debounce1(boolean one)
{
{
boolean current1 = digitalRead(BUTTON); // Read the button state
if (one != current1) // If it's different...
{
current1 = digitalRead(BUTTON); // Read it again
}
return current1; // Return the current value
}
}
boolean debounce2(boolean two)
{
{
boolean current2 = digitalRead(buttonPin1); // Read the button state
if (two != current2) // If it's different...
{
current2 = digitalRead(buttonPin1); // Read it again
}
return current2; // Return the current value
}
}
/***************************************************************************/
void setMode(int mode)
{
//RED
if (mode == 1)
{
color(255, 0, 0);
}
//GREEN
else if (mode == 2)
{
color(0, 255, 0);
}
//BLUE
else if (mode == 3)
{
color(0, 0, 255);
}
//PURPLE (RED+BLUE)
else if (mode == 4)
{
color(255, 0, 255);
}
//TEAL (BLUE+GREEN)
else if (mode == 5)
{
color(0, 255, 255);
}
//ORANGE (GREEN+RED)
else if (mode == 6)
{
color(255, 150, 0);
}
//WHITE (GREEN+RED+BLUE)
else if (mode == 7)
{
color(255, 255, 255);
}
//OFF (mode = 0)
else
{
color(0, 0, 0);
}
}
void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function
{
analogWrite(RLED, red);
analogWrite(GLED, green);
analogWrite(BLED, blue);
}
void setModeone(int mode)
{
if (mode == 1)
{
if (ledMode == 1){
for (int thisNote = 0; thisNote < notesr * 2; thisNote = thisNote + 2) {
dividerr = rnotes[thisNote + 1];
if (dividerr > 0) {
noteDurationr = (wholenoter) / dividerr;
} else if (dividerr < 0) {
noteDurationr = (wholenoter) / abs(dividerr);
noteDurationr *= 1.5;
}
{
const long interval = noteDurationr;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (SpeakerState == LOW) {
tone(SPEAKER, rnotes[thisNote],noteDurationr * 0.9);
} else {
noTone(SPEAKER);
digitalWrite(SPEAKER, SpeakerState);
}
}
}
}
}
else if (ledMode == 2){
for (int thisNote = 0; thisNote < notesg * 2; thisNote = thisNote + 2) {
dividerg = gnotes[thisNote + 1];
if (dividerg > 0) {
noteDurationg = (wholenoteg) / dividerg;
} else if (dividerg < 0) {
noteDurationg = (wholenoteg) / abs(dividerg);
noteDurationg *= 1.5;
}
{
const long interval = noteDurationg;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (SpeakerState == LOW) {
tone(SPEAKER, gnotes[thisNote], noteDurationg * 0.9);
} else {
noTone(SPEAKER);
digitalWrite(SPEAKER, SpeakerState);
}
}
}
}
}
else if (ledMode == 3){
for (int thisNote = 0; thisNote < notesb * 2; thisNote = thisNote + 2) {
dividerb = bnotes[thisNote + 1];
if (dividerb > 0) {
noteDurationb = (wholenoteb) / dividerb;
} else if (dividerg < 0) {
noteDurationb = (wholenoteb) / abs(dividerb);
noteDurationb *= 1.5;
}
{
const long interval = noteDurationb;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (SpeakerState == LOW) {
tone(SPEAKER, bnotes[thisNote], noteDurationb * 0.9);
} else {
noTone(SPEAKER);
digitalWrite(SPEAKER, SpeakerState);
}
}
}
}
}
else if (ledMode == 4){
for (int thisNote = 0; thisNote < notesp * 2; thisNote = thisNote + 2) {
dividerp = pnotes[thisNote + 1];
if (dividerp > 0) {
noteDurationp = (wholenotep) / dividerp;
} else if (dividerg < 0) {
noteDurationp = (wholenotep) / abs(dividerp);
noteDurationp *= 1.5;
}
{
const long interval = noteDurationp;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (SpeakerState == LOW) {
tone(SPEAKER, pnotes[thisNote], noteDurationp * 0.9);
} else {
noTone(SPEAKER);
digitalWrite(SPEAKER, SpeakerState);
}
}
}
}
}
else if (ledMode == 5){
for (int thisNote = 0; thisNote < notest * 2; thisNote = thisNote + 2) {
dividert = tnotes[thisNote + 1];
if (dividert > 0) {
noteDurationt = (wholenotet) / dividert;
} else if (dividert < 0) {
noteDurationt = (wholenotet) / abs(dividert);
noteDurationt *= 1.5;
}
{
const long interval = noteDurationt;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (SpeakerState == LOW) {
tone(SPEAKER, tnotes[thisNote], noteDurationt * 0.9);
} else {
noTone(SPEAKER);
digitalWrite(SPEAKER, SpeakerState);
}
}
}
}
}
else if (ledMode == 6){
for (int thisNote = 0; thisNote < noteso * 2; thisNote = thisNote + 2) {
dividero = onotes[thisNote + 1];
if (dividero > 0) {
noteDurationo = (wholenoteo) / dividero;
} else if (dividero < 0) {
noteDurationo = (wholenoteo) / abs(dividero);
noteDurationo *= 1.5;
}
{
const long interval = noteDurationo;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (SpeakerState == LOW) {
tone(SPEAKER, onotes[thisNote], noteDurationo * 0.9);
} else {
noTone(SPEAKER);
digitalWrite(SPEAKER, SpeakerState);
}
}
}
}
}
else if (ledMode == 7){
for (int thisNote = 0; thisNote < notesw * 2; thisNote = thisNote + 2) {
dividerw = wnotes[thisNote + 1];
if (dividerw > 0) {
noteDurationw = (wholenotew) / dividerw;
} else if (dividerw < 0) {
noteDurationw = (wholenotew) / abs(dividerw);
noteDurationw *= 1.5;
}
{
const long interval = noteDurationw;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (SpeakerState == LOW) {
tone(SPEAKER, wnotes[thisNote], noteDurationw * 0.9);
} else {
noTone(SPEAKER);
digitalWrite(SPEAKER, SpeakerState);
}
}
}
}
}
}
//OFF (mode = 0)
else
{
noTone(SPEAKER);
}
}
/******************************************************/
const int analogPin = 0;//the analog input pin attach to
const int ledPin = 8;//the led attach to
int inputValue = 0;//variable to store the value coming from sensor
int outputValue = 0;//variable to store the output value
/******************************************/
void loop()
{
{ currentButton = debounce1(lastButton); // Read debounced state
if (lastButton == LOW && currentButton == HIGH) // If it was pressed...
{
ledMode++; // Increment the LED value
}
lastButton = currentButton; // Reset button value
if (ledMode == 8) ledMode = 0;
setMode(ledMode); // Change the LED state
}
{ currentButtonone = debounce2(lastButtonone); // Read debounced state
if (lastButtonone == LOW && currentButtonone == HIGH) // If it was pressed...
{
play++; // Increment the LED value
}
lastButtonone = currentButtonone; // Reset button value
if (play == 2) play = 0;
setModeone(play); // Change the LED state
}
}