/*
Command 072 - Fade a specified LED fade up and down
This program sends a commnand to the IRCF360 to fade up and down. By entering a number
from 0-7 the respective LED starts fading up and down.
Byte 1 = 72 which triggers the command
Byte 2 = Speed of fading - Changing this value will change the speed 10 is a good value to start with
Byte 3 = Is the LED to fade O=North, 1=NE, 2=E, 3=SE, 4=S, 5=SW, 6=W, 7=W
Byte 4 = 255 = continuous
Byte 4 = other number is on-shot i.e. will execute only once the stop
Thanks to Greg Smith for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 15 June, 2011
by Colin Bacon
This example code is in the public domain.
http://www.robotmaker.eu/products-2/ircf360/ircf360-command-overview/072---ircf-command---circular-display---single-led-fade
*/
int BYTE1 =72; // Command
int BYTE2 =10; // Speed of fade. 100 is very fast 5 is very slow
int BYTE3 =0; // LED number default value
int BYTE4 =255; // 255 = continuous other = one-shot
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
{
delay (1000);
Serial.print(BYTE1, BYTE);
Serial.print(BYTE2,BYTE);
Serial.print(BYTE3,BYTE);
Serial.print(BYTE4,BYTE);
}
}
void loop()
{
// if we get a valid byte, read the LED to illuminate:
while (Serial.available() == 0); //keep looping until a value is entered
// convert the ascii value to decimal value and assign it to the LED
BYTE3 = Serial.read() -'0';
if ((BYTE3 <=7) && (BYTE3 >=0))
{
// sending any byte will stop the existing sequence
Serial.print(BYTE1, BYTE);
}
//Let the ping-pong routine run for 1 second
delay (1000);
{
//Send details of the new sequence
Serial.print(BYTE1, BYTE);
Serial.print(BYTE2,BYTE);
Serial.print(BYTE3,BYTE);
Serial.print(BYTE4,BYTE);
}
// Flush and rubbish
Serial.flush();
}