30 Second Timer + LED Display + Pager Motor HELP!!


hello members,

firstly, mods wasn't sure sub-forum should open thread in. please move per necessary.

description of project:
our project consists of transmitting device (atmega128 mc) , receiving device (atmega168 [arduino mini]).
the transmitter going send signals (characters/strings) on rf , receiver execute few commands.

intro of sorts:
the receiver have pager motor, 2 digit led display , led. led display countdown specific time , cause pager motor vibrate , reset countdown. simultaneously, receiver 'listening' commands transmitter , execute specific commands - vibrate pager motor and/or reset countdown.

problem:

i have managed code using serial library listens input. if press / receives 'a' activates pager motor 5000 ms  and if press / receives 'b' starts countdown. still need incorporate led display have segments turn on , off.

i realized when using countdown, can't simultaneously execute other actions. read on interrupt commands, barely understand had do. i, also, read on how change values in timer2 , had hard time understanding you. (pardon me being tissue engineer).

what hoping for, way keep countdown running , when want pager motor vibrate, execute command without interrupting countdown.

i appreciate guys! in advance.

regards,
shubs

code: [select]
/* include softwareserial library can use functions:
#include <softwareserial.h>
*/

int rxpin = 0;
int txpin = 1;
int motpin = 7;
int ledpin = 13;
metro led_metro = metro(500);

/* set new serial port
softwareserial rfserial =  softwareserial(rxpin, txpin);
*/
byte pinstate = 0;


void setup()  {
 // define pin modes tx, rx, led pins:
 pinmode(rxpin, input);
 pinmode(txpin, output);
 pinmode(motpin, output);
 pinmode(ledpin, output);
 // set data rate softwareserial port
 serial.begin(9600);
}

void loop() {
 // listen new serial coming in:
 if (serial.available() > 0)
 {  char somechar = serial.read();
   // print out character:
   serial.print(somechar);
   // toggle led see thing's alive.  
   // led go on every other character received:
   if (somechar == 'a'){
     motor(ledpin);
   }
   if (somechar == 'b'){
     timer(5000);
   }
 }

}

void timer(int time)
{
 for(int = 0; <= time; i++){
   serial.println(i);
   ledblink();
     }
     digitalwrite(ledpin, low);
 }

void ledblink(){
 if (led_metro.check() == 1) { // check if metro has passed it's interval .
   digitalwrite(ledpin,!digitalread(ledpin)); // change state of pin 13.
   if (digitalread(ledpin)==high)  {
     led_metro.interval(500); // if pin high, set interval 0.5 seconds.
   }
   else {
     led_metro.interval(500); // if pin low, set interval 0.5 second.
   }
 }
}
void motor(int pinnum)
{
 digitalwrite(pinnum, high);
 delaymicroseconds(5000);
 digitalwrite(pinnum, low);
}


my approach not use interrupts, use state machines checked every milli second.

in pseudo code in main loop havesomething like:

code: [select]

prvmilli = 0;

loop(){
 crtmilli = millis();
 if (crtmilli != prvmilli) {
   prvmilli = crtmilli;    

   // bit runs every milli second - check things do

  if (serial.available){
    serial character
    if (serchar = 'a'){
     do thing
    }
    if (serchar = 'b'){
       do 'b' thing
    }
   
    timerval --;
    if (timerval =<0){
       timerval = 5000;

       do teh 5 second timer stuff
     }
     etc.

  }
 }
}


all processes implemented state machines none of states taking longer milli second - way there no clock cycles wasted.

i hope clear(ish).

sorry not putting proper code - first coding language isn't c.

mike





Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > 30 Second Timer + LED Display + Pager Motor HELP!!


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums