You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TeensyStripController.ino
+82-3Lines changed: 82 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
** ----------------------
4
4
**
5
5
** This Sketch turns a Teensy 3.1, 3.2 or later into a controller for WS2811/WS2812 based led strips.
6
-
** This strip controller was originally designed supported by the Direct Output Framework, but since
6
+
** This strip controller was originally designed for use with the Direct Output Framework, but since
7
7
** the communication protocol is simple and communication uses the virtual com port of the Teensy
8
8
** it should be easy to controll the strips from other applications as well.
9
9
**
@@ -39,16 +39,26 @@
39
39
//Definiton of Major and Minor part of the firmware version. This value can be received using the V command.
40
40
//If something is changed in the code the number should be increased.
41
41
#defineFirmwareVersionMajor1
42
-
#defineFirmwareVersionMinor1
42
+
#defineFirmwareVersionMinor2
43
43
44
44
//Defines the max number of leds which is allowed per ledstrip.
45
-
//This number is fine for Teensy 3.2 & 3.1. For newer Teensy versions (they dont exists yet) it might be possible to increase this number.
45
+
//This number is fine for Teensy 3.2, 3.1. For newer Teensy versions (they dont exists yet) it might be possible to increase this number.
46
46
#defineMaxLedsPerStrip1100
47
47
48
+
//Defines the Pinnumber to which the built in led of the Teensy is connected.
49
+
//For Teensy 3.2, 3.1 this is pin 13, if you use a newer Teensy version (not available at the time of writing) you might need to change this number.
50
+
#defineLedPin13
51
+
52
+
48
53
//Memory buffers for the OctoWS2811 lib
49
54
DMAMEM int displayMemory[MaxLedsPerStrip*6];
50
55
int drawingMemory[MaxLedsPerStrip*6];
51
56
57
+
//Variable used to control the blinking and flickering of the led of the Teensy
58
+
elapsedMillis BlinkTimer;
59
+
int BlinkMode;
60
+
elapsedMillis BlinkModeTimeoutTimer;
61
+
52
62
//Config definition for the OctoWS2811 lib
53
63
constint config = WS2811_RGB | WS2811_800kHz; //Dont change the color order (even if your strip are GRB). DOF takes care of this issue (see config of ledstrip toy)
54
64
@@ -65,6 +75,10 @@ void setup() {
65
75
leds.begin();
66
76
leds.show();
67
77
78
+
//Initialize the led pin
79
+
pinMode(LedPin,OUTPUT);
80
+
81
+
SetBlinkMode(0);
68
82
}
69
83
70
84
//Main loop of the programm gets called again and again.
@@ -109,9 +123,74 @@ void loop() {
109
123
Nack();
110
124
break;
111
125
}
126
+
127
+
128
+
SetBlinkMode(1);
129
+
130
+
131
+
}
132
+
Blink();
133
+
}
134
+
135
+
136
+
//Sets the mode for the blinking of the led
137
+
voidSetBlinkMode(int Mode) {
138
+
BlinkMode=Mode;
139
+
BlinkModeTimeoutTimer=0;
140
+
}
141
+
142
+
//Controls the blinking of the led
143
+
voidBlink() {
144
+
switch(BlinkMode) {
145
+
case0:
146
+
//Blinkmode 0 is only active after the start of the Teensy until the first command is received.
147
+
if(BlinkTimer<1500) {
148
+
digitalWrite(LedPin,0);
149
+
} elseif(BlinkTimer<1600) {
150
+
digitalWrite(LedPin,1);
151
+
} else {
152
+
BlinkTimer=0;
153
+
digitalWrite(LedPin,0);
154
+
}
155
+
break;
156
+
case1:
157
+
//Blinkmode 1 is activated when the Teensy receives a command
158
+
//Mode expires 500ms after the last command has been received resp. mode has been set
159
+
if(BlinkTimer>30) {
160
+
BlinkTimer=0;
161
+
digitalWrite(LedPin,!digitalRead(LedPin));
162
+
}
163
+
if(BlinkModeTimeoutTimer>500) {
164
+
SetBlinkMode(2);
165
+
}
166
+
break;
167
+
case2:
168
+
//Blinkmode 2 is active while the Teensy is waiting for more commands
169
+
if(BlinkTimer<1500) {
170
+
digitalWrite(LedPin,0);
171
+
} elseif(BlinkTimer<1600) {
172
+
digitalWrite(LedPin,1);
173
+
} elseif(BlinkTimer<1700) {
174
+
digitalWrite(LedPin,0);
175
+
} elseif(BlinkTimer<1800) {
176
+
digitalWrite(LedPin,1);
177
+
}else {
178
+
BlinkTimer=0;
179
+
digitalWrite(LedPin,0);
180
+
}
181
+
default:
182
+
//This should never be active
183
+
//The code is only here to make it easier to determine if a wrong Blinkcode has been set
0 commit comments