Hello
Anyone familiar with the popular 315Mhz RF Transmitter and Receiver Modules FS1000A
I am using vitualwire examples to send and receive messages. The examples work fine. But when I added an additional task to display LEDs strip light sequence, the program does not seem to find transmitted data in the buffer most of the time. It is running InOutMiniSequence all the time. The timer calls the getData but it finds data once in a while. From time to time it execute LRDirectionWithStop.
What am i missing???
[code]#include <TimerOne.h>
#include <PololuLedStrip.h>
#define LED_SIGNAL_PIN 12
#include <VirtualWire.h>
PololuLedStrip<LED_SIGNAL_PIN> ledStrip;
#define LED_COUNT 42
rgb_color colors[LED_COUNT];
const int led_pin = 13;
const int receive_pin = 11;
int icount = 0;
void setup()
{
delay(100);
Serial.begin(9600); // Debugging only
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
pinMode(led_pin, OUTPUT);
Timer1.initialize(150000);
Timer1.attachInterrupt(getData); // blinkLED to run every 0.15 seconds
}
volatile unsigned long iDirection = 0; // use volatile for shared variables
volatile unsigned long iSide = 0; // use volatile for shared variables
void loop()
{
Serial.println(iDirection);
if (iDirection == 71)
{
Serial.println(“Right”);
LRDirectionWithStop(2,0,30) ;
}
else if (iDirection == 83)
{
Serial.println(“STOP”);
StopLight(3,2,2); //Stop
}
else {
InOutMiniSequence (0,0,175,50);
}
delay(100);
}
void getData(void)
{
delay(500);
noInterrupts();
iDirection = 0;
iSide = 0;
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
Serial.print("Getting Data ");
Serial.println(icount);
if (vw_get_message(buf, &buflen)) // Non-blocking
{
digitalWrite(led_pin, HIGH); // Flash a light to show received good message
char sDirection={buf[6]};
char sSide={buf[5]};
iDirection = sDirection;
iSide = sSide;
Serial.print("direction is ");
Serial.println(sDirection);
digitalWrite(led_pin, LOW);
}
interrupts();
icount =++icount;
}
//====== LED runs up and Down
void InOutMiniSequence(int iRed , int iBlue , int iGreen , int idelay)
{
// handleNextPatternButton();
//Run up
for (int g = 0; g < 4; g ++ )
{
colors[ g] = colors[ 6-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[ 7+g] = colors[13-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[14+g] = colors[20-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[21+g] = colors[27-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[28+g] = colors[34-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[35+g] = colors[41-g] =(rgb_color){ iRed, iBlue, iGreen };
ledStrip.write(colors, LED_COUNT);
delay (idelay);
colors[ g] = colors[ 6-g] =(rgb_color){ 0, 0,0 };
colors[ 7+g] = colors[13-g] =(rgb_color){ 0, 0,0 };
colors[14+g] = colors[20-g] =(rgb_color){ 0, 0,0 };
colors[21+g] = colors[27-g] =(rgb_color){ 0, 0,0 };
colors[28+g] = colors[34-g] =(rgb_color){ 0, 0,0 };
colors[35+g] = colors[41-g] =(rgb_color){ 0, 0,0 };
ledStrip.write(colors, LED_COUNT);
delay (10);
}
//Reverse
for (int g = 0; g < 4; g ++ )
{
colors[ 3-g] = colors[ 3+g] =(rgb_color){ iRed, iBlue, iGreen };
colors[10+g] = colors[10-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[17+g] = colors[17-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[24+g] = colors[24-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[31+g] = colors[31-g] =(rgb_color){ iRed, iBlue, iGreen };
colors[38+g] = colors[38-g] =(rgb_color){ iRed, iBlue, iGreen };
ledStrip.write(colors, LED_COUNT);
delay (idelay);
colors[ 3-g] = colors[ 3+g] =(rgb_color){ 0,0,0 };
colors[10+g] = colors[10-g] =(rgb_color){ 0,0,0 };
colors[17+g] = colors[17-g] =(rgb_color){ 0,0,0 };
colors[24+g] = colors[24-g] =(rgb_color){ 0,0,0 };
colors[31+g] = colors[31-g] =(rgb_color){ 0,0,0 };
colors[38+g] = colors[38-g] =(rgb_color){ 0,0,0 };
ledStrip.write(colors, LED_COUNT);
delay (10);
}
}[/code]