Your task is being posted in rapid succession so all of your tasks are being completed before your timer fires. Also when you call a timer.start() to an already running timer then the previous timer is stopped and a new one is started. So in your example if n=5 then the execution will happen like this.
call Leds.greenOn();
call greenTimer.start(TIMER_ONE_SHOT, 25);
call Leds.greenOn();
call greenTimer.start(TIMER_ONE_SHOT, 25); (timer stopped and new 25 ms timer started)
call greenTimer.start(TIMER_ONE_SHOT, 25); (timer stopped and new 25 ms timer started)
call Leds.greenOn();
call greenTimer.start(TIMER_ONE_SHOT, 25); (timer restarted)
call Leds.greenOn();
call greenTimer.start(TIMER_ONE_SHOT, 25); (timer restarted)
call Leds.greenOn();
call greenTimer.start(TIMER_ONE_SHOT, 25); (timer restarted)
... (25 ms pass) ...
greenTimer.fired()
call Leds.greenOff();
So increasing the value of n would only make the green LED stay on just a little bit longer (the time added to process the instructions n times).
You could post the task, use Leds.greenToggle() then start a timer and post the task again from inside the greenTimer.fired() event. To limit the number of times the LED toggles you could count off how many times you have started the timer in the task, using a global variable of course. Let me know if this helps you out.
Chris
On 11/21/05, Alex Mason <[EMAIL PROTECTED]> wrote:
Hi,
Probably a very simple question (as usual!) but I can't seem to find an
understandable answer.
I was creating a small demo with my motes to show radio comms receiving,
performing a task and then acknowledging completion. In doing this, I
wanted to flash the Leds quickly in succession. So, I created a task to do
this - for example:
task void flashGreen() {
call Leds.greenOn();
call greenTimer.start(TIMER_ONE_SHOT, 25);
}
...
event result_t greenTimer.fired() {
call Leds.greenOff();
return SUCCESS;
}
Then, I can just use "post flashGreen" to flash the Led. However, the
problem I have is that I want to flash the Led 'n' number of times so I
tried:
for (i = 0; i < n; i++) {
post flashGreen;
}
However, this just flashes the Led once, regardless of the value of 'n'. I
have the feeling the problem is because of the task being posted too many
times in quick succession - but on the other hand I was under the impression
that tasks are processed FIFO, so I'm a little confused. Of course, this
isn't a major problem (I don't need the Leds to flash in practice) but it
would be nice to know what is causing the problem for future reference. I
have tried atomic execution also, but this made no difference (unless I am
using it incorrectly).
Cheers,
----------
Alex Mason
Postgraduate Research
RFID & Wireless Sensor Networks
Liverpool John Moores University
Email: [EMAIL PROTECTED]
Phone: +447886389484
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________ Tinyos-help mailing list [email protected] https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
