Just a way to have fun with the speaker for the more musically inclined:
http://www.youtube.com/watch?v=kEGwcimYa98
(A marginally better demonstration of the capabilities -
http://www.youtube.com/watch?v=-n0Iqr82iSo)
It's not the smoothest instrument in the world, but I invite everyone to use this code (or write your own), and record yourself playing a song! (Anyone who plays Final Countdown will be... unoriginal.)
Code:
/*
AURA - Auckland University Robotics Association
Button Controlled Vex Speaker
Uses the (7 of the) 8 buttons on the newer (cortex/VEXnet) controllers
*/
task main() {
//Frequencies are rounded to the nearest 10hz so they sound a bit smoother (and hopefully not off-pitch)
int notearray[3][22] = {
{0,490,520,550,550,590,620,620,660,670,660,700,740,740,780,830,830,880,930,930,990,1050},
{0,990,1050,1110,1110,1170,1240,1240,1320,1400,1320,1400,1480,1480,1570,1660,1660,1760,1860,1860,1980,2100},
{0,1980,2090,2220,2220,2350,2490,2490,2640,2790,2640,2790,2960,2960,3140,3320,3320,3520,3730,3730,3950,4190}};
//Yes, I know that I doubled up on the frequencies above, and could have made life a bit easier for myself
int note = 0;
int octave = 0;
while(1) {
if (vexRT[Btn7L] == 1) {
if (vexRT[Btn6U] == 1) {
note = 3; //Cs
} else if (vexRT[Btn6D] == 1) {
note = 1; //Cf
} else {
note = 2; //C
}
} else if(vexRT[Btn7U] == 1) {
if (vexRT[Btn6U] == 1) {
note = 6; //Ds
} else if (vexRT[Btn6D] == 1) {
note = 4; //Df
} else {
note = 5; //D
}
} else if (vexRT[Btn7D] == 1) {
if (vexRT[Btn6U] == 1) {
note = 9; //Es
} else if (vexRT[Btn6D] == 1) {
note = 7; //Ef
} else {
note = 8; //E
}
} else if (vexRT[Btn8L] == 1) {
if (vexRT[Btn6U] == 1) {
note = 12; //Fs
} else if (vexRT[Btn6D] == 1) {
note = 10; //Ff
} else {
note = 11; //F
}
} else if (vexRT[Btn8U] == 1) {
if (vexRT[Btn6U] == 1) {
note = 15; //Gs
} else if (vexRT[Btn6D] == 1) {
note = 13; //Gf
} else {
note = 14; //G
}
} else if (vexRT[Btn8D] == 1) {
if (vexRT[Btn6U] == 1) {
note = 18; //As
} else if (vexRT[Btn6D] == 1) {
note = 16; //Af
} else {
note = 17; //A
}
} else if (vexRT[Btn8R] == 1) {
if (vexRT[Btn6U] == 1) {
note = 21; //Bs
} else if (vexRT[Btn6D] == 1) {
note = 19; //Bf
} else {
note = 20; //B
}
} else {
note = 0; //NONE
}
if (vexRT[Btn5U] == 1) {
if (octave < 2) {
octave++;
wait10Msec(25);
}
} else if (vexRT[Btn5D] == 1) {
if (octave > 0) {
octave--;
wait10Msec(25);
}
} else {
octave = octave;
}
PlayTone(notearray[octave][note],10);
wait10Msec(10);
}
}