|
Page 1 of 1
|
[ 5 posts ] |
|
| Author |
Message |
|
Thekid986
Rookie
Joined: Wed Feb 08, 2012 8:28 pm Posts: 13
|
 Different tasks?
Hey everyone, im sorry if i bug you with all my questions. I am very interested in robotc and want to learn as much as possible. My question for today is; What is a way to run two things at once. I have my program that is the important part with all the functions and acions and stuff, I also want to run a second program that make the nxt beep out music by playing timed beeps at different frequencies. I have all the code but i dont know how to integrate them. I need to be able to drive and do everything else while the nxt plays music. I have to make it so the music doesnt effect the main task at all; but i also want the music to play and if it switched tasks or something the timeing would be off. I need to like run the music in the bacground but have it not effect the code. Any suggestions, also when i get the code done i will post it on here so everyone can see  Thanks Thekid986
|
| Tue Feb 14, 2012 4:22 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Different tasks?
I'm sure that you're not bugging anyone with questions. After all, that's what these forums are here for. If you want an introductory tutorial in multitasking, you may want to look at this compilation in the VEX forums: http://www.vexforum.com/showthread.php?t=53551
_________________ sudo rm -rf /
|
| Tue Feb 14, 2012 7:04 pm |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Different tasks?
I seldom play with the NXT tone functions except for playing warning sounds. But if I remember it correctly, the PlayTone function in RobotC will queue up the tones to be played. I don't have RobotC in front of me at the moment so I can't verify it. In theory, you can just execute the PlayTone functions one after the other so they will be queued up and executed in a timely manner. Having said that, I don't know how big is the RobotC tone queue. If you play a long song, it may overflow the queue. On the other hand, it is not really that difficult to write a task to play songs in the background. For example:  |  |  |  | Code: #define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0])) int Notes[] = { 988, 988, 0, 988, 784, 988, 1175, 0, 783, 0, 784, 0, 783, 0, 659, 0, 880, 987, 932, 880, ... }; int Durations[] = { 14, 14, 7, 27, 14, 27, 27, 27, 27, 27, 27, 14, 27, 14, 27, 14, 27, 27, 14, 27, ... }; int index = 0;
task SongTask() { while (index < ARRAYSIZE(Notes)) { if (!bSoundActive) { PlayTone(Notes[index], Durations[index]); index++; } } }
task main() { StartTask(SongTask); while (true) { // // do other robot tasks here. // } }
|  |  |  |  |
EDIT: Thanks Xander, I have corrected the bSoundActive variable.
Last edited by MHTS on Wed Feb 15, 2012 6:51 am, edited 2 times in total.
|
| Tue Feb 14, 2012 9:39 pm |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2906 Location: Rotterdam, The Netherlands
|
 Re: Different tasks?
It's bSoundActive and it's a boolean variable  - Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Wed Feb 15, 2012 6:17 am |
|
 |
|
Thekid986
Rookie
Joined: Wed Feb 08, 2012 8:28 pm Posts: 13
|
 Re: Different tasks?
Thank you guys so much I think i got the kinks worked out now! Thekid986
|
| Wed Feb 15, 2012 11:28 am |
|
|
|
Page 1 of 1
|
[ 5 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 3 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
|
|