Skip to content

Commit 0a3663a

Browse files
TomTom
authored andcommitted
Added support for led on the Teensy board
1 parent c72dd61 commit 0a3663a

File tree

1 file changed

+82
-3
lines changed

1 file changed

+82
-3
lines changed

TeensyStripController.ino

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** ----------------------
44
**
55
** 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
77
** the communication protocol is simple and communication uses the virtual com port of the Teensy
88
** it should be easy to controll the strips from other applications as well.
99
**
@@ -39,16 +39,26 @@
3939
//Definiton of Major and Minor part of the firmware version. This value can be received using the V command.
4040
//If something is changed in the code the number should be increased.
4141
#define FirmwareVersionMajor 1
42-
#define FirmwareVersionMinor 1
42+
#define FirmwareVersionMinor 2
4343

4444
//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.
4646
#define MaxLedsPerStrip 1100
4747

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+
#define LedPin 13
51+
52+
4853
//Memory buffers for the OctoWS2811 lib
4954
DMAMEM int displayMemory[MaxLedsPerStrip*6];
5055
int drawingMemory[MaxLedsPerStrip*6];
5156

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+
5262
//Config definition for the OctoWS2811 lib
5363
const int 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)
5464

@@ -65,6 +75,10 @@ void setup() {
6575
leds.begin();
6676
leds.show();
6777

78+
//Initialize the led pin
79+
pinMode(LedPin,OUTPUT);
80+
81+
SetBlinkMode(0);
6882
}
6983

7084
//Main loop of the programm gets called again and again.
@@ -109,9 +123,74 @@ void loop() {
109123
Nack();
110124
break;
111125
}
126+
127+
128+
SetBlinkMode(1);
129+
130+
131+
}
132+
Blink();
133+
}
134+
135+
136+
//Sets the mode for the blinking of the led
137+
void SetBlinkMode(int Mode) {
138+
BlinkMode=Mode;
139+
BlinkModeTimeoutTimer=0;
140+
}
141+
142+
//Controls the blinking of the led
143+
void Blink() {
144+
switch(BlinkMode) {
145+
case 0:
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+
} else if(BlinkTimer<1600) {
150+
digitalWrite(LedPin,1);
151+
} else {
152+
BlinkTimer=0;
153+
digitalWrite(LedPin,0);
154+
}
155+
break;
156+
case 1:
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+
case 2:
168+
//Blinkmode 2 is active while the Teensy is waiting for more commands
169+
if(BlinkTimer<1500) {
170+
digitalWrite(LedPin,0);
171+
} else if(BlinkTimer<1600) {
172+
digitalWrite(LedPin,1);
173+
} else if(BlinkTimer<1700) {
174+
digitalWrite(LedPin,0);
175+
} else if(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
184+
if(BlinkTimer>2000) {
185+
BlinkTimer=0;
186+
digitalWrite(LedPin,!digitalRead(LedPin));
187+
}
188+
break;
112189
}
190+
113191
}
114192

193+
115194
//Outputs the data in the ram to the ledstrips
116195
void OutputData() {
117196
leds.show();

0 commit comments

Comments
 (0)