Welcome, Guest. Please login or register.
Did you miss your activation email?

Username: Password:


Pages: [1]   Go Down

Author Topic: Using SENSOR_TIMER  (Read 5142 times)

Getorix

  • Following the footsteps
  • * Posts: 12
  • Male
Using SENSOR_TIMER
« on: December 23, 2009, 04:25:35 PM »

TASK:
Make Pleo to behave according to the timer events.

SOLUTION:
First of all you have to put this into public init() function of sensors.p file:
Code: [Select]
set_timer_interval(1000); // Event every 1 second (1000ms)
Then you should add common sensor handler like:
Code: [Select]
new name[32];
switch (sensor)
{
case SENSOR_TIMER:
{
sensor_get_name(sensor, name);
printf("+ <on_sensor> %d, %s, %d\n", time, name, value);
// DO SOMETHING
printf("- <on_sensor> %d, %s, %d\n", time, name, value);
}
}

Finally you should disable timer in public close() function:
Code: [Select]
set_timer_interval(0); // Disable Timer
Enjoy
« Last Edit: December 24, 2009, 12:46:15 AM by Getorix »
Logged


InmemoryofRomeo

  • Global Moderator
  • Pleo Grand Master RB
  • * Posts: 6903
  • au Female
  • Pleo(s): Lilo, Stitch, Pleakley, Jumba, Nani, Yuki, Angus, Pluto
  • : 2011 winner2009 winnerTomato Harvest Festivals
  • SAVE THE EARTH It's the only planet with chocolate
    • Professor
    • Wile_E_Coyote
    • Marcie
Re: Using SENSOR_TIMER
« Reply #1 on: December 25, 2009, 11:05:22 PM »

The code worked spot on, thank you so much, I will upload a newer version of the Christmas skit very soon :)
Logged
Eagerly awaiting Vector and Blue!
Pages: [1]   Go Up
 

SimplePortal 2.3.5 © 2008-2012, SimplePortal