Mercurial > code > home > repos > light9
annotate rgbled/nanostrip.cc @ 2394:7578f855d18b
deps fix
author | drewp@bigasterisk.com |
---|---|
date | Tue, 14 May 2024 14:46:56 -0700 |
parents | b7fb7b2649fd |
children |
rev | line source |
---|---|
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
1 #include <Arduino.h> |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
2 #include <Adafruit_NeoPixel.h> |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
3 |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
4 /* |
1251 | 5 PWM is available on 3,5,6,9,10,11 |
6 | |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
7 Pin D3: blacklight pwm |
1251 | 8 Pin D4: neo strip 1 |
9 Pin D6: R | |
10 Pin D8: neo strip 2 | |
11 Pin D9: G | |
12 Pin D10: B | |
13 Pin D11: blacklight 2 | |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
14 */ |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
15 |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
16 |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
17 // Parameter 1 = number of pixels in strip |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
18 // Parameter 2 = pin number (most are valid) |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
19 // Parameter 3 = pixel type flags, add together as needed: |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
20 // NEO_RGB Pixels are wired for RGB bitstream |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
21 // NEO_GRB Pixels are wired for GRB bitstream |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
22 // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
23 // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) |
1251 | 24 Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(50, 4, NEO_RGB + NEO_KHZ800); |
25 Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(50, 8, NEO_RGB + NEO_KHZ800); | |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
26 |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
27 #define debugLed 13 |
1251 | 28 |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
29 void intro() { |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
30 uint32_t red = strip0.Color(255,0,0), black = strip0.Color(0,0,0); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
31 for (Adafruit_NeoPixel* strip = &strip0; strip != &strip1; strip = &strip1) { |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
32 strip->setPixelColor(0, red); strip->show(); delay(100); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
33 strip->setPixelColor(0, black); strip->show(); delay(100); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
34 strip->setPixelColor(0, red); strip->show(); delay(100); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
35 strip->setPixelColor(0, black); strip->show(); delay(100); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
36 } |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
37 } |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
38 |
1251 | 39 void setStrip(Adafruit_NeoPixel* strip) { |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
40 digitalWrite(debugLed, 1); |
1251 | 41 for (uint8_t i=0; i < strip->numPixels(); i++) { |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
42 while (Serial.available() < 3) { |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
43 } |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
44 byte r = Serial.read(); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
45 byte g = Serial.read(); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
46 byte b = Serial.read(); |
1251 | 47 strip->setPixelColor(i, strip->Color(g, r, b)); |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
48 } |
1251 | 49 strip->show(); |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
50 |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
51 digitalWrite(debugLed, 0); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
52 } |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
53 |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
54 int main(void) { |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
55 init(); |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
56 pinMode(debugLed, OUTPUT); |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
57 |
1255 | 58 |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
59 strip0.begin(); |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
60 strip1.begin(); |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
61 intro(); |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
62 Serial.begin(115200); |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
63 |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
64 uint8_t i; |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
65 while (1) { |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
66 while (Serial.available() <= 2) { |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
67 } |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
68 i = Serial.read(); |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
69 if (i != 0x60) { |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
70 continue; |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
71 } |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
72 i = Serial.read(); // command |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
73 if (i == 0) { // set strip: 0x60 0x00 <numPixels * 3 bytes> |
1251 | 74 setStrip(&strip0); |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
75 } else if (i == 1) { // strip 1 |
1251 | 76 setStrip(&strip1); |
77 } else if (i == 2) { // set pwm on uv1: 0x60 0x02 <level> | |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
78 while (Serial.available() < 1) { |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
79 } |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
80 analogWrite(3, Serial.read()); |
1251 | 81 } else if (i == 3) { // set pwm on uv2: 0x60 0x03 <level> |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
82 while (Serial.available() < 1) { |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
83 } |
1251 | 84 analogWrite(11, Serial.read()); |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
85 } else if (i == 4) { // set r/g/b: 0x60 0x04 <r> <g> <b> |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
86 while (Serial.available() < 3) { |
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
87 } |
1251 | 88 analogWrite(6, Serial.read()); |
1241
e588ede64e0e
update rgbled arduino code to more devices
drewp@bigasterisk.com
parents:
1231
diff
changeset
|
89 analogWrite(9, Serial.read()); |
1251 | 90 analogWrite(10, Serial.read()); |
1231
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
91 } else { |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
92 // unknown command |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
93 } |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
94 } |
ef4ae15f2661
copy in rgb led program for arduino
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
95 } |