The arduino in my head...DragonDruino all the way...
DragonDruino may be a alias I should go after... Anyhow, After asher put my head together last year, I spend some time retrofitting LEDs and using a ASK receiver to make it sync with the tail (ASK transmitter).
For open-sourceness, My "Sketch" Below:
/*
Dennis Liang
© Drakes Computers
LED driver controler, 10 wires.
RGB
1,2,3,4,5,6,7
*/
#include <EEPROM.h>
#include <VirtualWire.h>
//SPike Config
const byte left_head =9;
const byte right_head =7;
const byte first_spike =4;
const byte second_spike = 8;
//byte third_spike = A3;
//byte forth_spike = A1;
//byte fifth_spike = 11;
const byte red_pin = 6;
const byte green_pin = 5;
const byte blue_pin = 3;
///End of spike config
//Fan Driver
const byte fan_wire = 10;
//End FAN
//RX
const byte rx_1 = 12;
const byte rx_2 = 13;
const byte rx_3 = A0;
const byte rx_4 = A1;
//ENDRX
boolean disable_power= false;
byte mode = 0;
byte color_red = 100;
byte color_green = 100;
byte color_blue = 100;
#define mode_address 1
#define pwr_address 0
#define red_address 2
#define green_address 3
#define blue_address 4
void setup() {
// nothing happens in setup
//pinMode(10,OUTPUT);
//digitalWrite(10,HIGH);
Serial.begin(115200);
// Serial.print(F("$$$"));
// delay(100);
// Serial.println(F("SN,DrakeTail"));
// delay(100);
// Serial.println(F("---"));
//
pinMode(red_pin,OUTPUT);
pinMode(green_pin,OUTPUT);
pinMode(blue_pin,OUTPUT);
pinMode(left_head,INPUT); //left blade
pinMode(right_head,INPUT); //Right blade
pinMode(second_spike,INPUT); //2nd spike
pinMode(first_spike,INPUT); //1st spike
pinMode(fan_wire, OUTPUT); //FAN support PWM
digitalWrite(fan_wire, LOW);
//Setup RX reciever
pinMode(rx_1, OUTPUT);
pinMode(rx_2, INPUT); //Recieve Pin
pinMode(rx_3, INPUT); //may use to generate randome number with
pinMode(rx_4, OUTPUT); //VCC
digitalWrite(rx_1, LOW);
digitalWrite(rx_4, HIGH); //Low to Disable reciver
vw_set_rx_pin(rx_2);
vw_setup(1000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
randomSeed(analogRead(5)); //initilize the randomizer
mode = EEPROM.read(mode_address); //restore mode
if (EEPROM.read(pwr_address) == 1) //restore power
disable_power = true;
//restore color setting
if (EEPROM.read(red_address) > 100)
color_red = 100;
else
color_red = EEPROM.read(red_address);
if (EEPROM.read(green_address) > 100)
color_green = 100;
else
color_green = EEPROM.read(green_address);
if (EEPROM.read(blue_address) > 100)
color_blue = 100;
else
color_blue = EEPROM.read(red_address);
//Serial.setTimeout(3000);
Serial.print(F("Head controller\r\n©2013 Drakes Computers,\r\nCompiled on\r\n"));
Serial.println(F(__DATE__));
Serial.println(F(__TIME__));
Serial.println(F("Ready."));
}
void loop() {
menu(); ///drive on screen menu
if (!disable_power)
switch (mode)
{
case 0:
light_spike((byte)random(0, 7), (byte)random(0, 100), (byte)random(0, 100), (byte)random(0, 100), 1);
break;
case 1:
down_strobe();
break;
case 2:
up_strobe();
break;
case 3:
ping_pong();
break;
case 4:
//Mode used to switch LEDS on and off?
break;
}
//menu area
virtualwire();
}
void virtualwire()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking , should check for a 5 byte lenfth packet
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print((char)buf[i], DEC);
Serial.print(' ');
}
Serial.println();
byte parseint_color = 0;
switch (buf[0])
{
case 'r':
case 'R':
parseint_color = buf[1];
if (parseint_color > 0)
color_red = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'g':
case 'G':
parseint_color = buf[1];
if (parseint_color > 0)
color_green = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'b':
case 'B':
parseint_color = buf[1];
if (parseint_color > 0)
color_blue = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 200:
//this case we send light commands directly to led
light_spike(buf[1], buf[2], buf[3], buf[4], 1);
break;
default: //Hanles everything else for menu commands
parsemenu(buf[0]);
}
}
//bufflen should have 5 parts
}
void down_strobe()
{
static int led_position;
//static unsigned long previousMillis;
//if(millis() - previousMillis > 100) {
// save the last time you blinked the LED
// previousMillis = millis();
light_spike(led_position, color_red, color_green, color_blue, 1); //Change LED position
led_position--;
//}
if (led_position < 0)
led_position = 6;
}
void up_strobe()
{
static int led_position;
//static unsigned long previousMillis;
//if(millis() - previousMillis > 100) {
// save the last time you blinked the LED
// previousMillis = millis();
light_spike(led_position, color_red, color_green, color_blue, 1); //Change LED position
led_position++;
//}
if (led_position > 7)
led_position = 0;
}
void ping_pong()
{
static int led_position;
static boolean led_direction; //goes in reverse
//static unsigned long previousMillis;
//if(millis() - previousMillis > 100) {
// save the last time you blinked the LED
// previousMillis = millis();
light_spike(led_position, color_red, color_green, color_blue, 1); //Change LED position
if (led_direction)
led_position--;
else
led_position++;
//}
if (led_position > 7)
led_direction = true;
if (led_position < 0)
led_direction = false;
}
void menu()
{
if (Serial.available() > 0) {
byte serialbyte = Serial.read();
//send command to interpreter
parsemenu(serialbyte);
//
} //serial port
}
void parsemenu(byte serialbyte)
{
int parseint_color = 0;
switch (serialbyte) {
case '0': //Changes lighting modes
mode = 0;
Serial.println(F("Mode:0 Random lights and colors"));
EEPROM.write(mode_address,mode);
break;
case '1':
mode = 1;
Serial.println(F("Mode:1 Strobe up"));
EEPROM.write(mode_address,mode);
break;
case '2':
mode = 2;
Serial.println(F("Mode:2 Strobe down"));
EEPROM.write(mode_address,mode);
break;
case '3':
mode = 3; //***********************
Serial.println(F("Mode:3 Ping pong"));
EEPROM.write(mode_address,mode);
break;
/*case '4':
mode = 4; //***********************
Serial.println(F("Mode:4 Manual"));
EEPROM.write(mode_address,mode);
break;
*/
case 'Q':
case 'q':
color_red++;
if (color_red > 100)
color_red = 100;
Serial.print(F("Color_red:")); Serial.println(color_red,DEC);
break;
case 'W':
case 'w':
color_green++;
if (color_green > 100)
color_green = 100;
Serial.print(F("Color_green:")); Serial.println(color_green,DEC);
break;
case 'E':
case 'e':
color_blue++;
if (color_blue > 100)
color_blue = 100;
Serial.print(F("Color_blue:")); Serial.println(color_blue,DEC);
break;
case 'A':
case 'a':
color_red--;
if (color_red > 100)
color_red = 0; //using wrap around
Serial.print(F("Color_red:")); Serial.println(color_red,DEC);
break;
case 'S':
case 's':
color_green--;
if (color_green > 100)
color_green = 0; //using wrap around
Serial.print(F("Color_green:")); Serial.println(color_green,DEC);
break;
case 'D':
case 'd':
color_blue--;
if (color_blue > 100)
color_blue = 0; //using wrap around
Serial.print(F("Color_blue:")); Serial.println(color_blue,DEC);
break;
case 'R':
case 'r':
Serial.print(F("RED:\nEnter number(1-101):"));
parseint_color = Serial.parseInt();
if (parseint_color > 0)
color_red = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'G':
case 'g':
Serial.print(F("GREEN:\nEnter number(1-101):"));
parseint_color = Serial.parseInt();
if (parseint_color > 0)
color_green = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'B':
case 'b':
Serial.print(F("BLUE:\nEnter number(1-101):"));
parseint_color = Serial.parseInt();
if (parseint_color > 0)
color_blue = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'p':
case 'P':
Serial.println(F("LED's on!"));
disable_power = false;
EEPROM.write(pwr_address,(byte)disable_power);
break;
case 'O':
case 'o':
Serial.println(F("LED's off!"));
disable_power = true;
EEPROM.write(pwr_address,(byte)disable_power);
break;
case 'f':
case 'F':
Serial.println(F("FAN's on!"));
digitalWrite(fan_wire, HIGH);
break;
case 'v':
case 'V':
Serial.println(F("FAN's off!"));
digitalWrite(fan_wire, LOW);
break;
case 'C':
case 'c':
EEPROM.write(red_address,color_red);
EEPROM.write(green_address,color_green);
EEPROM.write(blue_address,color_blue);
Serial.println(F("Settings Saved!"));
break;
case 'L':
case 'l':
Serial.print("SETTINGS:");
Serial.print(mode, DEC);
Serial.print(",");
Serial.print(color_red+1, DEC);
Serial.print(",");
Serial.print(color_green+1, DEC);
Serial.print(",");
Serial.print(color_blue+1, DEC);
Serial.println(".");
break;
//main menu
case '?':
case 'h':
case '\r':
Serial.println(F("*******************"));
Serial.println(F("Available Commands:"));
Serial.println(F("p-Power On"));
Serial.println(F("o-Power Off"));
Serial.println(F("0-Random Flicker"));
Serial.println(F("1-Stobe Up"));
Serial.println(F("2-Stobe Down"));
Serial.println(F("3-Ping Pong"));
//Serial.println(F("4-Manual"));
Serial.println(F("f-FAN ON"));
Serial.println(F("v-FAN OFF"));
Serial.println(F("q-RED++"));
Serial.println(F("w-GREEN++"));
Serial.println(F("e-BLUE++"));
Serial.println(F("a-RED--"));
Serial.println(F("s-GREEN--"));
Serial.println(F("d-BLUE--"));
Serial.println(F("r-RED, set"));
Serial.println(F("g-GREEN, set"));
Serial.println(F("b-BLUE, set"));
Serial.println(F("c-Save color changes."));
Serial.println(F("l-Get settings"));
Serial.print(F("Power:"));
if (disable_power)
Serial.println(F("OFF!"));
else
Serial.println(F("ON!"));
Serial.print(F("Mode:"));
Serial.println(mode,DEC);
Serial.print(F("COLOR:"));
Serial.print(color_red+1, DEC);
Serial.print(",");
Serial.print(color_green+1, DEC);
Serial.print(",");
Serial.print(color_blue+1, DEC);
Serial.println(".");
// Serial.println(F("S-Scan for signal"));
}
}
//void fade()
//{
//
// // fade in from min to max in increments of 5 points:
// for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// // sets the value (range from 0 to 255):
// analogWrite(6, fadeValue); //Red
// analogWrite(3, fadeValue);
// analogWrite(5, fadeValue);
// // wait for 30 milliseconds to see the dimming effect
// delay(1);
// }
//
// // fade out from max to min in increments of 5 points:
// for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// // sets the value (range from 0 to 255):
// analogWrite(6, fadeValue);
// analogWrite(3, fadeValue);
// analogWrite(5, fadeValue);
// // wait for 30 milliseconds to see the dimming effect
// delay(1);
// }
//}
void pulsecolor(byte red, byte green, byte blue, int time)
{
/*
Pulse to that color. Pulse time depends on time x color steps
TODO write this in a nonblocking thread otherwise it takes about 260ms or 1/4 second to flash the spike.
*/
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(red_pin, fadeValue * red / 100); //Red
analogWrite(green_pin, fadeValue * green / 100); //Green
analogWrite(blue_pin, fadeValue * blue / 100); //Blue
// wait for 30 milliseconds to see the dimming effect
// Serial.print("Fading value:");
// Serial.println(fadeValue * red / 100);
delay(time);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(red_pin, fadeValue * red / 100); //Red
analogWrite(green_pin, fadeValue * green / 100); //Green
analogWrite(blue_pin, fadeValue * blue / 100); //blue
// wait for 30 milliseconds to see the dimming effect
delay(time);
}
}
void light_spike(byte spike, byte red, byte green, byte blue, int time)
{
//Flashes Color of each spike
switch (spike){
case 0:
digitalWrite(first_spike,LOW);
pinMode(first_spike,OUTPUT);
//Serial.println("First Spike");
pulsecolor(red, green, blue, time);
pinMode(first_spike,INPUT);
break;
case 1:
digitalWrite(second_spike,LOW);
pinMode(second_spike,OUTPUT);
//Serial.println("Second Spike");
pulsecolor(red, green, blue, time);
pinMode(second_spike,INPUT);
break;
// case 2:
// digitalWrite(third_spike,LOW);
// pinMode(third_spike,OUTPUT);
// //Serial.println("Third Spike");
// pulsecolor(red, green, blue, time);
// pinMode(third_spike,INPUT);
// break;
// case 3:
// digitalWrite(forth_spike,LOW);
// pinMode(forth_spike,OUTPUT);
// //Serial.println("Forth Spike");
// pulsecolor(red, green, blue, time);
// pinMode(forth_spike,INPUT);
// break;
// case 4:
// digitalWrite(fifth_spike,LOW);
// pinMode(fifth_spike,OUTPUT);
// //Serial.println("Fifth Spike");
// pulsecolor(red, green, blue, time);
// pinMode(fifth_spike,INPUT);
// break;
case 5:
digitalWrite(left_head,LOW);
pinMode(left_head,OUTPUT);
//Serial.println("Left Blade");
pulsecolor(red, green, blue, time);
pinMode(left_head,INPUT);
break;
case 6:
digitalWrite(right_head,LOW);
pinMode(right_head,OUTPUT);
//Serial.println("Right Blade");
pulsecolor(red, green, blue, time);
pinMode(right_head,INPUT);
break;
}
}
For open-sourceness, My "Sketch" Below:
/*
Dennis Liang
© Drakes Computers
LED driver controler, 10 wires.
RGB
1,2,3,4,5,6,7
*/
#include <EEPROM.h>
#include <VirtualWire.h>
//SPike Config
const byte left_head =9;
const byte right_head =7;
const byte first_spike =4;
const byte second_spike = 8;
//byte third_spike = A3;
//byte forth_spike = A1;
//byte fifth_spike = 11;
const byte red_pin = 6;
const byte green_pin = 5;
const byte blue_pin = 3;
///End of spike config
//Fan Driver
const byte fan_wire = 10;
//End FAN
//RX
const byte rx_1 = 12;
const byte rx_2 = 13;
const byte rx_3 = A0;
const byte rx_4 = A1;
//ENDRX
boolean disable_power= false;
byte mode = 0;
byte color_red = 100;
byte color_green = 100;
byte color_blue = 100;
#define mode_address 1
#define pwr_address 0
#define red_address 2
#define green_address 3
#define blue_address 4
void setup() {
// nothing happens in setup
//pinMode(10,OUTPUT);
//digitalWrite(10,HIGH);
Serial.begin(115200);
// Serial.print(F("$$$"));
// delay(100);
// Serial.println(F("SN,DrakeTail"));
// delay(100);
// Serial.println(F("---"));
//
pinMode(red_pin,OUTPUT);
pinMode(green_pin,OUTPUT);
pinMode(blue_pin,OUTPUT);
pinMode(left_head,INPUT); //left blade
pinMode(right_head,INPUT); //Right blade
pinMode(second_spike,INPUT); //2nd spike
pinMode(first_spike,INPUT); //1st spike
pinMode(fan_wire, OUTPUT); //FAN support PWM
digitalWrite(fan_wire, LOW);
//Setup RX reciever
pinMode(rx_1, OUTPUT);
pinMode(rx_2, INPUT); //Recieve Pin
pinMode(rx_3, INPUT); //may use to generate randome number with
pinMode(rx_4, OUTPUT); //VCC
digitalWrite(rx_1, LOW);
digitalWrite(rx_4, HIGH); //Low to Disable reciver
vw_set_rx_pin(rx_2);
vw_setup(1000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
randomSeed(analogRead(5)); //initilize the randomizer
mode = EEPROM.read(mode_address); //restore mode
if (EEPROM.read(pwr_address) == 1) //restore power
disable_power = true;
//restore color setting
if (EEPROM.read(red_address) > 100)
color_red = 100;
else
color_red = EEPROM.read(red_address);
if (EEPROM.read(green_address) > 100)
color_green = 100;
else
color_green = EEPROM.read(green_address);
if (EEPROM.read(blue_address) > 100)
color_blue = 100;
else
color_blue = EEPROM.read(red_address);
//Serial.setTimeout(3000);
Serial.print(F("Head controller\r\n©2013 Drakes Computers,\r\nCompiled on\r\n"));
Serial.println(F(__DATE__));
Serial.println(F(__TIME__));
Serial.println(F("Ready."));
}
void loop() {
menu(); ///drive on screen menu
if (!disable_power)
switch (mode)
{
case 0:
light_spike((byte)random(0, 7), (byte)random(0, 100), (byte)random(0, 100), (byte)random(0, 100), 1);
break;
case 1:
down_strobe();
break;
case 2:
up_strobe();
break;
case 3:
ping_pong();
break;
case 4:
//Mode used to switch LEDS on and off?
break;
}
//menu area
virtualwire();
}
void virtualwire()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking , should check for a 5 byte lenfth packet
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print((char)buf[i], DEC);
Serial.print(' ');
}
Serial.println();
byte parseint_color = 0;
switch (buf[0])
{
case 'r':
case 'R':
parseint_color = buf[1];
if (parseint_color > 0)
color_red = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'g':
case 'G':
parseint_color = buf[1];
if (parseint_color > 0)
color_green = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'b':
case 'B':
parseint_color = buf[1];
if (parseint_color > 0)
color_blue = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 200:
//this case we send light commands directly to led
light_spike(buf[1], buf[2], buf[3], buf[4], 1);
break;
default: //Hanles everything else for menu commands
parsemenu(buf[0]);
}
}
//bufflen should have 5 parts
}
void down_strobe()
{
static int led_position;
//static unsigned long previousMillis;
//if(millis() - previousMillis > 100) {
// save the last time you blinked the LED
// previousMillis = millis();
light_spike(led_position, color_red, color_green, color_blue, 1); //Change LED position
led_position--;
//}
if (led_position < 0)
led_position = 6;
}
void up_strobe()
{
static int led_position;
//static unsigned long previousMillis;
//if(millis() - previousMillis > 100) {
// save the last time you blinked the LED
// previousMillis = millis();
light_spike(led_position, color_red, color_green, color_blue, 1); //Change LED position
led_position++;
//}
if (led_position > 7)
led_position = 0;
}
void ping_pong()
{
static int led_position;
static boolean led_direction; //goes in reverse
//static unsigned long previousMillis;
//if(millis() - previousMillis > 100) {
// save the last time you blinked the LED
// previousMillis = millis();
light_spike(led_position, color_red, color_green, color_blue, 1); //Change LED position
if (led_direction)
led_position--;
else
led_position++;
//}
if (led_position > 7)
led_direction = true;
if (led_position < 0)
led_direction = false;
}
void menu()
{
if (Serial.available() > 0) {
byte serialbyte = Serial.read();
//send command to interpreter
parsemenu(serialbyte);
//
} //serial port
}
void parsemenu(byte serialbyte)
{
int parseint_color = 0;
switch (serialbyte) {
case '0': //Changes lighting modes
mode = 0;
Serial.println(F("Mode:0 Random lights and colors"));
EEPROM.write(mode_address,mode);
break;
case '1':
mode = 1;
Serial.println(F("Mode:1 Strobe up"));
EEPROM.write(mode_address,mode);
break;
case '2':
mode = 2;
Serial.println(F("Mode:2 Strobe down"));
EEPROM.write(mode_address,mode);
break;
case '3':
mode = 3; //***********************
Serial.println(F("Mode:3 Ping pong"));
EEPROM.write(mode_address,mode);
break;
/*case '4':
mode = 4; //***********************
Serial.println(F("Mode:4 Manual"));
EEPROM.write(mode_address,mode);
break;
*/
case 'Q':
case 'q':
color_red++;
if (color_red > 100)
color_red = 100;
Serial.print(F("Color_red:")); Serial.println(color_red,DEC);
break;
case 'W':
case 'w':
color_green++;
if (color_green > 100)
color_green = 100;
Serial.print(F("Color_green:")); Serial.println(color_green,DEC);
break;
case 'E':
case 'e':
color_blue++;
if (color_blue > 100)
color_blue = 100;
Serial.print(F("Color_blue:")); Serial.println(color_blue,DEC);
break;
case 'A':
case 'a':
color_red--;
if (color_red > 100)
color_red = 0; //using wrap around
Serial.print(F("Color_red:")); Serial.println(color_red,DEC);
break;
case 'S':
case 's':
color_green--;
if (color_green > 100)
color_green = 0; //using wrap around
Serial.print(F("Color_green:")); Serial.println(color_green,DEC);
break;
case 'D':
case 'd':
color_blue--;
if (color_blue > 100)
color_blue = 0; //using wrap around
Serial.print(F("Color_blue:")); Serial.println(color_blue,DEC);
break;
case 'R':
case 'r':
Serial.print(F("RED:\nEnter number(1-101):"));
parseint_color = Serial.parseInt();
if (parseint_color > 0)
color_red = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'G':
case 'g':
Serial.print(F("GREEN:\nEnter number(1-101):"));
parseint_color = Serial.parseInt();
if (parseint_color > 0)
color_green = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'B':
case 'b':
Serial.print(F("BLUE:\nEnter number(1-101):"));
parseint_color = Serial.parseInt();
if (parseint_color > 0)
color_blue = parseint_color-1;
Serial.println(parseint_color,DEC);
break;
case 'p':
case 'P':
Serial.println(F("LED's on!"));
disable_power = false;
EEPROM.write(pwr_address,(byte)disable_power);
break;
case 'O':
case 'o':
Serial.println(F("LED's off!"));
disable_power = true;
EEPROM.write(pwr_address,(byte)disable_power);
break;
case 'f':
case 'F':
Serial.println(F("FAN's on!"));
digitalWrite(fan_wire, HIGH);
break;
case 'v':
case 'V':
Serial.println(F("FAN's off!"));
digitalWrite(fan_wire, LOW);
break;
case 'C':
case 'c':
EEPROM.write(red_address,color_red);
EEPROM.write(green_address,color_green);
EEPROM.write(blue_address,color_blue);
Serial.println(F("Settings Saved!"));
break;
case 'L':
case 'l':
Serial.print("SETTINGS:");
Serial.print(mode, DEC);
Serial.print(",");
Serial.print(color_red+1, DEC);
Serial.print(",");
Serial.print(color_green+1, DEC);
Serial.print(",");
Serial.print(color_blue+1, DEC);
Serial.println(".");
break;
//main menu
case '?':
case 'h':
case '\r':
Serial.println(F("*******************"));
Serial.println(F("Available Commands:"));
Serial.println(F("p-Power On"));
Serial.println(F("o-Power Off"));
Serial.println(F("0-Random Flicker"));
Serial.println(F("1-Stobe Up"));
Serial.println(F("2-Stobe Down"));
Serial.println(F("3-Ping Pong"));
//Serial.println(F("4-Manual"));
Serial.println(F("f-FAN ON"));
Serial.println(F("v-FAN OFF"));
Serial.println(F("q-RED++"));
Serial.println(F("w-GREEN++"));
Serial.println(F("e-BLUE++"));
Serial.println(F("a-RED--"));
Serial.println(F("s-GREEN--"));
Serial.println(F("d-BLUE--"));
Serial.println(F("r-RED, set"));
Serial.println(F("g-GREEN, set"));
Serial.println(F("b-BLUE, set"));
Serial.println(F("c-Save color changes."));
Serial.println(F("l-Get settings"));
Serial.print(F("Power:"));
if (disable_power)
Serial.println(F("OFF!"));
else
Serial.println(F("ON!"));
Serial.print(F("Mode:"));
Serial.println(mode,DEC);
Serial.print(F("COLOR:"));
Serial.print(color_red+1, DEC);
Serial.print(",");
Serial.print(color_green+1, DEC);
Serial.print(",");
Serial.print(color_blue+1, DEC);
Serial.println(".");
// Serial.println(F("S-Scan for signal"));
}
}
//void fade()
//{
//
// // fade in from min to max in increments of 5 points:
// for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// // sets the value (range from 0 to 255):
// analogWrite(6, fadeValue); //Red
// analogWrite(3, fadeValue);
// analogWrite(5, fadeValue);
// // wait for 30 milliseconds to see the dimming effect
// delay(1);
// }
//
// // fade out from max to min in increments of 5 points:
// for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// // sets the value (range from 0 to 255):
// analogWrite(6, fadeValue);
// analogWrite(3, fadeValue);
// analogWrite(5, fadeValue);
// // wait for 30 milliseconds to see the dimming effect
// delay(1);
// }
//}
void pulsecolor(byte red, byte green, byte blue, int time)
{
/*
Pulse to that color. Pulse time depends on time x color steps
TODO write this in a nonblocking thread otherwise it takes about 260ms or 1/4 second to flash the spike.
*/
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(red_pin, fadeValue * red / 100); //Red
analogWrite(green_pin, fadeValue * green / 100); //Green
analogWrite(blue_pin, fadeValue * blue / 100); //Blue
// wait for 30 milliseconds to see the dimming effect
// Serial.print("Fading value:");
// Serial.println(fadeValue * red / 100);
delay(time);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(red_pin, fadeValue * red / 100); //Red
analogWrite(green_pin, fadeValue * green / 100); //Green
analogWrite(blue_pin, fadeValue * blue / 100); //blue
// wait for 30 milliseconds to see the dimming effect
delay(time);
}
}
void light_spike(byte spike, byte red, byte green, byte blue, int time)
{
//Flashes Color of each spike
switch (spike){
case 0:
digitalWrite(first_spike,LOW);
pinMode(first_spike,OUTPUT);
//Serial.println("First Spike");
pulsecolor(red, green, blue, time);
pinMode(first_spike,INPUT);
break;
case 1:
digitalWrite(second_spike,LOW);
pinMode(second_spike,OUTPUT);
//Serial.println("Second Spike");
pulsecolor(red, green, blue, time);
pinMode(second_spike,INPUT);
break;
// case 2:
// digitalWrite(third_spike,LOW);
// pinMode(third_spike,OUTPUT);
// //Serial.println("Third Spike");
// pulsecolor(red, green, blue, time);
// pinMode(third_spike,INPUT);
// break;
// case 3:
// digitalWrite(forth_spike,LOW);
// pinMode(forth_spike,OUTPUT);
// //Serial.println("Forth Spike");
// pulsecolor(red, green, blue, time);
// pinMode(forth_spike,INPUT);
// break;
// case 4:
// digitalWrite(fifth_spike,LOW);
// pinMode(fifth_spike,OUTPUT);
// //Serial.println("Fifth Spike");
// pulsecolor(red, green, blue, time);
// pinMode(fifth_spike,INPUT);
// break;
case 5:
digitalWrite(left_head,LOW);
pinMode(left_head,OUTPUT);
//Serial.println("Left Blade");
pulsecolor(red, green, blue, time);
pinMode(left_head,INPUT);
break;
case 6:
digitalWrite(right_head,LOW);
pinMode(right_head,OUTPUT);
//Serial.println("Right Blade");
pulsecolor(red, green, blue, time);
pinMode(right_head,INPUT);
break;
}
}
Category Photography / Tutorials
Species Unspecified / Any
Size 1280 x 960px
File Size 390.5 kB
FA+

Comments