-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusbot.ino
140 lines (116 loc) · 2.93 KB
/
statusbot.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "application.h"
#include "LiquidCrystal/LiquidCrystal.h"
// Colors
#define RGB_COLOR_RED 0xFF0000ul
#define RGB_COLOR_GREEN 0x00FF00ul
#define RGB_COLOR_BLUE 0x0000FFul
#define RGB_COLOR_YELLOW 0xFFFF00ul
#define RGB_COLOR_CYAN 0x00FFFFul
#define RGB_COLOR_MAGENTA 0xFF00FFul
#define RGB_COLOR_WHITE 0xFFFFFFul
#define RGB_COLOR_ORANGE 0xFF6000ul
#define WIZARD_ORANGE 0xFF3f00ul
#define WIZARD_BLUE 0x285166ul
#define WIZARD_GRAY 0x515159ul
// Pins for backlight
#define R_PIN D0
#define G_PIN A0
#define B_PIN A1
// Make sure to update these to match how you've wired your pins.
// pinout on LCD [RS, EN, D4, D5, D6, D7];
LiquidCrystal lcd(A2, A3, D3, D4, D5, D6);
int brightness = 255;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
// Setup pinmodes
pinMode(R_PIN, OUTPUT);
pinMode(G_PIN, OUTPUT);
pinMode(B_PIN, OUTPUT);
Spark.function("backlight", netBacklight);
Spark.function("testLight", testBacklight);
Spark.function("printLCD", printLCD);
welcomeMessage();
}
void loop() {
}
void welcomeMessage() {
backlight(WIZARD_ORANGE);
lcd.clear();
lcd.print("Wizard Dev");
lcd.setCursor(0,1);
lcd.print("Hello Programs!");
delay(1000);
lcd.setCursor(0,1);
lcd.print("StatusBot Online");
}
int printLCD (String message) {
lcd.clear();
int nline = message.indexOf("\n");
if (nline == -1) {
lcd.print(message);
return 1;
}
lcd.print(message.substring(0,nline));
lcd.setCursor(0,1);
lcd.print(message.substring(nline+1));
return 1;
}
int netBacklight(String args) {
char color[7]; // six hex and null
args.toCharArray(color, sizeof(color));
backlight(strtoul(color,0, 16));
return 1;
}
int testBacklight() {
return testBacklight("");
}
int testBacklight(String args) {
backlight(RGB_COLOR_RED);
delay(500);
backlight(RGB_COLOR_GREEN);
delay(500);
backlight(RGB_COLOR_BLUE);
delay(500);
backlight(RGB_COLOR_YELLOW);
delay(500);
backlight(RGB_COLOR_CYAN);
delay(500);
backlight(RGB_COLOR_MAGENTA);
delay(500);
backlight(RGB_COLOR_WHITE);
delay(500);
backlight(RGB_COLOR_ORANGE);
delay(500);
backlight(WIZARD_ORANGE);
delay(500);
backlight(WIZARD_BLUE);
delay(500);
backlight(WIZARD_GRAY);
delay(500);
welcomeMessage();
return 1;
}
void backlight(unsigned long rgb) {
int r = rgb >> 16 & 0x0000FF;
int g = rgb >> 8 & 0x0000FF;
int b = rgb & 0x0000FF;
// lcd.print("RGB #");
// lcd.print(r, HEX);
// lcd.print(g, HEX);
// lcd.print(b, HEX);
// normalize the colors a bit
// r = map(r, 0, 255, 0, 100);
// g = map(g, 0, 255, 0, 200);
// b = map(g, 0, 255, 0, 200);
r = map(r, 0, 255, 0, brightness);
g = map(g, 0, 255, 0, brightness);
b = map(b, 0, 255, 0, brightness);
// common anode so invert!
r = map(r, 0, 255, 255, 0);
g = map(g, 0, 255, 255, 0);
b = map(b, 0, 255, 255, 0);
analogWrite(R_PIN, r);
analogWrite(G_PIN, g);
analogWrite(B_PIN, b);
}