View unanswered posts | View active topics It is currently Thu Oct 23, 2014 6:14 am






Reply to topic  [ 4 posts ] 
Playing sounds on the VEX IQ 
Author Message
Rookie

Joined: Wed Feb 12, 2014 5:23 pm
Posts: 4
Post 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

_________________
Joe


Thu May 08, 2014 10:37 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu May 15, 2014 3:40 pm
Profile
Rookie

Joined: Wed Feb 12, 2014 5:23 pm
Posts: 4
Post 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.

_________________
Joe


Fri May 16, 2014 8:50 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu May 22, 2014 9:55 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.