-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoSerialLamp.ino
105 lines (82 loc) · 1.72 KB
/
ArduinoSerialLamp.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "FastLED.h"
#include "SerialCommand.h"
#define NUM_LEDS 16
#define LEDS_DATA_PIN A0
#define RANDOMSEED_PIN A5
SerialCommand SCmd;
byte mode = 0;
byte anim = 0;
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600); // a slow baudrate may slow down animations if printing from within the animation loop.
// set up serial commands callbacks
SCmd.addCommand("mode",cmd_mode);
SCmd.addCommand("anim",cmd_anim);
SCmd.addCommand("fadeb", cmd_anim_fade_blink);
SCmd.addDefaultHandler(cmd_unknown);
SCmd.setEOL('\n');
// initialize random
randomSeed(analogRead(RANDOMSEED_PIN));
FastLED.addLeds<NEOPIXEL, LEDS_DATA_PIN, GRB>(leds, NUM_LEDS);
fill_rainbow(&(leds[0]), 16, 0, 16);
FastLED.show();
delay(400);
fade_all_to_black(10);
Serial.println("000 Setup Complete");
}
void loop() {
// Read Serial Com
SCmd.readSerial();
Serial.println("001 Start Loop");
// if mode is 0, then pick a random animation
if(mode == 0)
anim = random(1,3);
if(mode == 1)
anim = 0;
switch(anim)
{
case 0:
default:
delay(500);
break;
case 1:
anim_wave(5, 60, 4);
break;
case 2:
anim_all_rainbow(300, 20);
break;
case 3:
anim_fade_blink(CHSV(144, 255, 1), 5);
break;
}
if(anim > 0)
fade_all_to_black(20);
Serial.println("002 End Loop");
}
void cmd_unknown()
{
Serial.println("404 Not Found");
}
void cmd_mode()
{
char *arg;
arg = SCmd.next();
if(arg != NULL)
{
mode = atoi(arg);
Serial.print("200 Mode set to: ");
Serial.println(mode);
}
}
void cmd_anim()
{
char *arg;
arg = SCmd.next();
if(arg != NULL)
{
mode = 2;
anim = atoi(arg);
Serial.print("200 Anim set to: ");
Serial.println(anim);
}
}