Skip to content

Commit 69dbd6e

Browse files
committed
arduino part for ledStrip extension
1 parent f76493b commit 69dbd6e

File tree

3 files changed

+131
-2
lines changed

3 files changed

+131
-2
lines changed

.cproject

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<option id="de.innot.avreclipse.toolchain.options.toolchain.size.app.release.2119422782" name="Print Size" superClass="de.innot.avreclipse.toolchain.options.toolchain.size.app.release"/>
2323
<option id="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release.1086980869" name="AVRDude" superClass="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release"/>
2424
<targetPlatform id="de.innot.avreclipse.targetplatform.winavr.app.release.929476625" name="AVR Cross-Target" superClass="de.innot.avreclipse.targetplatform.winavr.app.release"/>
25-
<builder arguments="TARGET=${ConfigName}" buildPath="${ProjDirPath}" command="make" id="de.innot.avreclipse.target.builder.winavr.app.release.718185616" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="AVR GNU Make Builder" superClass="de.innot.avreclipse.target.builder.winavr.app.release"/>
25+
<builder arguments="TARGET=${ConfigName} MAIN_SOURCE=${selected_resource_name}" buildPath="${ProjDirPath}" command="make" id="de.innot.avreclipse.target.builder.winavr.app.release.718185616" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="AVR GNU Make Builder" superClass="de.innot.avreclipse.target.builder.winavr.app.release"/>
2626
<tool id="de.innot.avreclipse.tool.assembler.winavr.app.release.6672668" name="AVR Assembler" superClass="de.innot.avreclipse.tool.assembler.winavr.app.release">
2727
<option id="de.innot.avreclipse.assembler.option.debug.level.1622353490" name="Generate Debugging Info" superClass="de.innot.avreclipse.assembler.option.debug.level" value="de.innot.avreclipse.assembler.option.debug.level.none" valueType="enumerated"/>
2828
<inputType id="de.innot.avreclipse.tool.assembler.input.167179968" superClass="de.innot.avreclipse.tool.assembler.input"/>

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export PROJECT_DIR := $(dir $(realpath ${MAKEFILE_LIST}))
66
CORE_DIR := ${PROJECT_DIR}../ArduinoCore/
77

88
# other arduino librairies project pathes this project depends on
9-
export DEPENDENCIES := ${CORE_DIR} ${CORE_DIR}../ArduinoLibs/
9+
export DEPENDENCIES := ${CORE_DIR} ${CORE_DIR}../ArduinoTools/
1010
# ${CORE_DIR}../ArduinoTools/
1111

1212
# generate assembler source code also

extensions/ledStrip/ledStrip.ino

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#ifdef PIF_TOOL_CHAIN
2+
#include <Arduino.h>
3+
// other includes with full pathes
4+
#include "ledStrip/strip.h"
5+
#else
6+
// other includes with short pathes
7+
// example : #include "led7.h"
8+
#include "strip.h"
9+
#endif
10+
11+
#ifndef DEFAULT_BAUDRATE
12+
#define DEFAULT_BAUDRATE 115200
13+
#endif
14+
15+
#define STRIP_PIN 8
16+
17+
void setup(void) {
18+
Serial.begin(DEFAULT_BAUDRATE);
19+
20+
Serial.println("ready");
21+
}
22+
23+
bool initialized = false;
24+
byte stripLen;
25+
byte light = 128;
26+
// buffer for command reads
27+
byte data[60];
28+
29+
bool readBytes(byte *buffer, int len, bool ascii) {
30+
if (ascii) {
31+
int i = 0, v = 0;
32+
while(i < len) {
33+
int c = Serial.read();
34+
if (c == -1 || c == '\r') {
35+
continue;
36+
} else if (c == ',' || c == ';' || c == '\n') {
37+
buffer[i] = v;
38+
v = 0;
39+
i++;
40+
} else if (c >= '0' && c <= '9') {
41+
v = v * 10 + c - '0';
42+
} else {
43+
return false;
44+
}
45+
}
46+
} else {
47+
int c;
48+
for (int i = 0; i < len; i++) {
49+
while((c = Serial.read()) == -1);
50+
buffer[i] = c;
51+
}
52+
}
53+
return true;
54+
}
55+
56+
void rainbow() {
57+
for (byte c = 1; c <= 255 - stripLen; c++) {
58+
for (byte p = 0; p < stripLen; p++) {
59+
stripSetH(p, c + p);
60+
}
61+
stripUpdate();
62+
delay(10);
63+
}
64+
}
65+
66+
void loop() {
67+
if (Serial.available()) {
68+
int b = Serial.read();
69+
switch(b) {
70+
case '!': // rainbow
71+
if (initialized) {
72+
rainbow();
73+
}
74+
break;
75+
case '?': // return status
76+
if (initialized) {
77+
Serial.println(stripLen);
78+
} else {
79+
Serial.println(0);
80+
}
81+
break;
82+
case 'i': // set strip len
83+
case 'I':
84+
if (readBytes(data, 1, b >= 'a' && b <= 'z')) {
85+
stripLen = data[0];
86+
stripInit(stripLen, STRIP_PIN);
87+
stripUpdate(); // Initialize all pixels to 'off'
88+
initialized = true;
89+
}
90+
break;
91+
case 'z': // switch off
92+
case 'Z': // switch off
93+
if (initialized) {
94+
stripOff();
95+
}
96+
break;
97+
case 'l': // set light intensity
98+
case 'L':
99+
if (readBytes(data, 1, b >= 'a' && b <= 'z')) {
100+
light = data[0];
101+
}
102+
break;
103+
case 'a': // all of same color
104+
case 'A':
105+
if (readBytes(data, 1, b >= 'a' && b <= 'z')) {
106+
Color c;
107+
HLtoRGB(data[0], light, &c);
108+
Serial.print(c.r); Serial.print(", ");
109+
Serial.print(c.g); Serial.print(", ");
110+
Serial.println(c.b);
111+
if (initialized) {
112+
stripAll(c);
113+
}
114+
}
115+
break;
116+
case 'c': // list of colors
117+
case 'C':
118+
if (readBytes(data, stripLen, b >= 'a' && b <= 'z')) {
119+
if (initialized) {
120+
for(int i = 0; i < stripLen; i++) {
121+
stripSetHL(i, data[i], light);
122+
}
123+
stripUpdate();
124+
}
125+
}
126+
break;
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)