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.

Dependencies:   mbed

Fork of app-board-RGB by Chris Styles

Files at this revision

API Documentation at this revision

Comitter:
ArthurSemjonov
Date:
Wed Feb 12 21:07:58 2014 +0000
Parent:
0:f86c572491c3
Commit message:
Change the name of the project;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
songs.cpp Show annotated file Show diff for this revision Revisions of this file
songs.h Show annotated file Show diff for this revision Revisions of this file
--- 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/songs.cpp	Wed Feb 12 21:07:58 2014 +0000
@@ -0,0 +1,32 @@
+/*
+ * song.cpp
+ *
+ *  Created on: Feb 11, 2014
+ *      Author: Artur Semjonov
+ */
+
+#include "mbed.h"
+#include "songs.h"
+
+
+PwmOut speaker(p26);
+DigitalIn off(p14); // middle joystick used to turn off the song
+Songs::Songs() {}
+
+void Songs::songOfMyPeople(float frequency[], float beat[])
+{
+   while(1) { //run infinetly unless interupted
+        for (int i=0; i<=8; i++) {
+            speaker.period(1/(2*frequency[i])); // set PWM period
+            speaker=0.5; // set duty cycle
+            wait(0.4*beat[i]);
+            if (off) {
+                speaker = 0; //reset speaker duty cycle
+                wait(2);     //delay for inferior humans
+                return; 
+            }
+        }
+        speaker = 0;
+        wait(0.25);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/songs.h	Wed Feb 12 21:07:58 2014 +0000
@@ -0,0 +1,24 @@
+/*
+ * song.h
+ *
+ *  Created on: Feb 11, 2014
+ *      Author: Artur Semjonov
+ */
+
+#ifndef SONG_H_
+#define SONG_H_
+
+class Songs
+{
+public:
+
+    Songs();
+    /* Plays the song based on frq and beat provided. Both frq and beat should be equal
+     * @param frequency[] array of frequencies of notes
+     * @param beat[] array of beats for the song
+     */
+    void songOfMyPeople(float frequency[], float beat[]);
+};
+
+
+#endif /* SONG_H_ */ 
\ No newline at end of file