Hello members,
Firstly, mods I wasn't too sure about which sub-forum I should open this thread in. Please move as per necessary.
Description of my project:
Our project consists of Transmitting device (ATmega128 MC) and a Receiving device (ATmega168 [Arduino Mini]).
The transmitter is going to send signals (characters/strings) over RF and receiver will execute a few commands.
Intro of sorts:
The receiver will have a pager motor, 2 digit LED Display and LED. LED display will countdown from a specific time and then cause the pager motor to vibrate and reset the countdown. Simultaneously, the receiver will be 'listening' for commands from the transmitter and execute specific commands - Vibrate pager motor and/or reset the countdown.
Problem:
I have managed to code something using the Serial library that listens for an input. If I press / it receives 'a' it activates the pager motor for a 5000 ms and if press / it receives 'b' it starts the countdown. I still need to incorporate the LED display have the segments turn on and off.
I realized that when I am using the countdown, I can't simultaneously execute other actions. I read up on interrupt commands, but could barely understand what I had to do. I, also, read up on how to change values in TIMER2 and I had hard time understanding that you. (Pardon me for being a Tissue engineer).
What I was hoping for, is a way that would keep the Countdown running and when I want the pager motor to vibrate, I could execute the command without interrupting the countdown.
I would appreciate any help from you guys! Thanks in advance.
Regards,
Shubs
/* include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>
*/
int rxPin = 0;
int txPin = 1;
int motPin = 7;
int ledPin = 13;
Metro led_metro = Metro(500);
/* set up a new serial port
SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);
*/
byte pinState = 0;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(motPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// set the data rate for the SoftwareSerial port
Serial.begin(9600);
}
void loop() {
// listen for new serial coming in:
if (Serial.available() > 0)
{ char someChar = Serial.read();
// print out the character:
Serial.print(someChar);
// toggle an LED just so you see the thing's alive.
// this LED will go on with every OTHER character received:
if (someChar == 'a'){
motor(ledPin);
}
if (someChar == 'b'){
timer(5000);
}
}
}
void timer(int time)
{
for(int i = 0; i <= time; i++){
Serial.println(i);
ledBlink();
}
digitalWrite(ledPin, LOW);
}
void ledBlink(){
if (led_metro.check() == 1) { // check if the metro has passed it's interval .
digitalWrite(ledPin,!digitalRead(ledPin)); // change the state of pin 13.
if (digitalRead(ledPin)==HIGH) {
led_metro.interval(500); // if the pin is HIGH, set the interval to 0.5 seconds.
}
else {
led_metro.interval(500); // if the pin is LOW, set the interval to 0.5 second.
}
}
}
void motor(int pinNum)
{
digitalWrite(pinNum, HIGH);
delayMicroseconds(5000);
digitalWrite(pinNum, LOW);
}