Uses 2 Potentiometers on the app-board to control red and green LED. Blue LED is controlled by using Up and Down buttons on the joystick. When Joystick is pressed down, the song will be played.
Fork of app-board-RGB by
Diff: main.cpp
- Revision:
- 1:4a2a53bbc623
- Parent:
- 0:f86c572491c3
diff -r f86c572491c3 -r 4a2a53bbc623 main.cpp --- a/main.cpp Mon Oct 15 12:19:12 2012 +0000 +++ b/main.cpp Wed Feb 12 21:07:58 2014 +0000 @@ -1,19 +1,40 @@ #include "mbed.h" +#include "songs.h" + -PwmOut r (p23); -PwmOut g (p24); -PwmOut b (p25); +/*******LED brightness value range from 0 to 1***********/ +PwmOut r (p23); //red +PwmOut g (p24); //greeb +PwmOut b (p25); //blue +/********************************************************/ +AnalogIn p1(p19); //Potentiometers left (red) +AnalogIn p2(p20); //Potentiometers right (green) +DigitalIn joyUP(p15); //Adds blue button +DigitalIn joyDOWN(p12); //Subtracts blue button +DigitalIn joyMID(p14); //Play the song button + +Songs play; //song object + +/*************************************I Am the Doctor***********************************/ +float frequency[]= {146.83, 164.81, 174.61, 196, 174.61 ,164.81, 146.83, 164.81, 146.83}; +float beat[]= {.9,.9,.9,0.5,.9,.9,.9,0.5,0.5, 0.5}; +/***************************************************************************************/ int main() { - r.period(0.001); while(1) { - for(float i = 0.0; i < 1.0 ; i += 0.001) { - float p = 3 * i; - r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); - g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); - b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; - wait (0.01); + r = p1; //read left potentiometer and set red light + g = p2; //read right potentiometer and set green light + if (joyUP) { + b = (b>0) ? b-0.01: b; //if blue > 0, then subtract 0.01 from brightness value + wait(0.01); + } else if (joyDOWN) { + b = (b<1) ? b+0.01: b; //if blue < 1, then add 0.01 to brightness value + wait(0.01); + } else if (joyMID) { + play.songOfMyPeople(frequency, beat); //play the song + wait(0.01); } + wait (0.01); } } \ No newline at end of file