ROBOTC.net forums
http://robotc.net/forums/

Playing sounds on the VEX IQ
http://robotc.net/forums/viewtopic.php?f=69&t=8734
Page 1 of 1

Author:  funkhouserj [ Thu May 08, 2014 10:37 am ]
Post subject:  Playing sounds on the VEX IQ

I built a drag racing Christmas tree using 4 led touch sensors. I want to play a note each time the light changes, but I can't get the VEX IQ to play a single note. Instead the note repeats 9 times. Honestly I don't fully understand the code to create the note. Please help!

Code:
TMusicalNotes nNoteToPlay = (3 << 4) + 5; //3rd Octave, Note 'E'
playNote(nNoteToPlay, 30); //Play the note for 300ms


Here is the full program. I don't have the sound playing after each light change yet. It just plays at the beginning.
Code:
#pragma config(Sensor, port1,  redLED,         sensorVexIQ_LED)
#pragma config(Sensor, port2,  yellow1LED,     sensorVexIQ_LED)
#pragma config(Sensor, port3,  yellow2LED,     sensorVexIQ_LED)
#pragma config(Sensor, port4,  greenLED,       sensorVexIQ_LED)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task warningSound()
{
   bPlaySounds = true;
   nVolume = 4;

   TMusicalNotes nNoteToPlay = (3 << 4) + 5; //3rd Octave, Note 'E'
   playNote(nNoteToPlay, 30); //Play the note for 300ms

}
task lightTree()
{
   setTouchLEDColor(redLED, colorRedViolet);
   sleep(2000);
   setTouchLEDColor(redLED, colorNone);

   setTouchLEDColor(yellow1LED, colorYellow);
   sleep(500);
   setTouchLEDColor(yellow1LED, colorNone);

   setTouchLEDColor(yellow2LED, colorYellow);
   sleep(500);
   setTouchLEDColor(yellow2LED, colorNone);

   setTouchLEDColor(greenLED, colorGreen);
   sleep(2000);
   setTouchLEDColor(greenLED, colorNone);
}

task main()
{
      while(true){
         if(getJoystickValue(BtnRDown) == 1){
            startTask(warningSound);
            startTask(lightTree);
         }
      }
}


Thanks,
Joe

Author:  Coder A [ Thu May 15, 2014 3:40 pm ]
Post subject:  Re: Playing sounds on the VEX IQ

When you say that the note repeats nine times, do you mean nine times per warningsound() call, or nine times per program execution?

Author:  funkhouserj [ Fri May 16, 2014 8:50 am ]
Post subject:  Re: Playing sounds on the VEX IQ

Thanks for the reply. The note repeats 9 times each time the right down button is pushed. Increasing or decreasing the time argument in the playNote function just speeds up or slows down the repeating note. The sample code doesn't show it, but the goal is to play a short note each time an LED lights up.

Author:  Coder A [ Thu May 22, 2014 9:55 am ]
Post subject:  Re: Playing sounds on the VEX IQ

That's strange. Have you tried using a different function to play the note? Maybe if you try playTone(frequency, duration), then it would work. I believe that Note E3 is frequency 165.

Does that help?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/