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

Committer:
ArthurSemjonov
Date:
Wed Feb 12 21:07:58 2014 +0000
Revision:
1:4a2a53bbc623
Change the name of the project;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ArthurSemjonov 1:4a2a53bbc623 1 /*
ArthurSemjonov 1:4a2a53bbc623 2 * song.cpp
ArthurSemjonov 1:4a2a53bbc623 3 *
ArthurSemjonov 1:4a2a53bbc623 4 * Created on: Feb 11, 2014
ArthurSemjonov 1:4a2a53bbc623 5 * Author: Artur Semjonov
ArthurSemjonov 1:4a2a53bbc623 6 */
ArthurSemjonov 1:4a2a53bbc623 7
ArthurSemjonov 1:4a2a53bbc623 8 #include "mbed.h"
ArthurSemjonov 1:4a2a53bbc623 9 #include "songs.h"
ArthurSemjonov 1:4a2a53bbc623 10
ArthurSemjonov 1:4a2a53bbc623 11
ArthurSemjonov 1:4a2a53bbc623 12 PwmOut speaker(p26);
ArthurSemjonov 1:4a2a53bbc623 13 DigitalIn off(p14); // middle joystick used to turn off the song
ArthurSemjonov 1:4a2a53bbc623 14 Songs::Songs() {}
ArthurSemjonov 1:4a2a53bbc623 15
ArthurSemjonov 1:4a2a53bbc623 16 void Songs::songOfMyPeople(float frequency[], float beat[])
ArthurSemjonov 1:4a2a53bbc623 17 {
ArthurSemjonov 1:4a2a53bbc623 18 while(1) { //run infinetly unless interupted
ArthurSemjonov 1:4a2a53bbc623 19 for (int i=0; i<=8; i++) {
ArthurSemjonov 1:4a2a53bbc623 20 speaker.period(1/(2*frequency[i])); // set PWM period
ArthurSemjonov 1:4a2a53bbc623 21 speaker=0.5; // set duty cycle
ArthurSemjonov 1:4a2a53bbc623 22 wait(0.4*beat[i]);
ArthurSemjonov 1:4a2a53bbc623 23 if (off) {
ArthurSemjonov 1:4a2a53bbc623 24 speaker = 0; //reset speaker duty cycle
ArthurSemjonov 1:4a2a53bbc623 25 wait(2); //delay for inferior humans
ArthurSemjonov 1:4a2a53bbc623 26 return;
ArthurSemjonov 1:4a2a53bbc623 27 }
ArthurSemjonov 1:4a2a53bbc623 28 }
ArthurSemjonov 1:4a2a53bbc623 29 speaker = 0;
ArthurSemjonov 1:4a2a53bbc623 30 wait(0.25);
ArthurSemjonov 1:4a2a53bbc623 31 }
ArthurSemjonov 1:4a2a53bbc623 32 }