Go Back   VEX Forum > Community > General Forum

General Forum Open Discussion of the VEX Robotics System that can be answered by anyone. VEX Robotics Engineers will not answer questions posted here; see Official VEX Technical Support below.

Reply
 
Thread Tools
  #1  
Old 05-10-2012, 04:24 AM
bobsalive bobsalive is offline
Senior Member
VEX # AURA
 
Join Date: Mar 2009
Location: Auckland, NZ
Posts: 321
Images: 4
Controlling the Speaker

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);

  }
}
__________________
Andrew - andrew.chen@aura.org.nz

Last edited by bobsalive; 05-10-2012 at 04:25 AM. Reason: Added another link
Reply With Quote
  #2  
Old 05-10-2012, 07:23 AM
fretless_kb fretless_kb is offline
Senior Member
VEX # 1166
 
Join Date: Jan 2010
Location: Parker CO
Posts: 282
Images: 6
Re: Controlling the Speaker

What a cool idea, we have a couple musicians on our team who might be very interested in this type of program. Thanks.
__________________
Kevin Barrett - Mentor - Team 1166
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 08:13 PM.


VEX and VEX Robotics are trademarks or service marks of Innovation First International, Inc.
Copyright © 2002-2013. All Rights Reserved. VEX Robotics, Inc. is a subsidiary of Innovation First International, Inc.
All other product names/marks of others are the property of their respective owners.