Skip to content

Commit f743477

Browse files
joshua-yangSeungChul Lee
authored andcommitted
examples: Add 4 examples for the new sensors
Change-Id: Ieb33512aa485000520c702417c79b4a84a27d732
1 parent d1493fb commit f743477

4 files changed

Lines changed: 587 additions & 0 deletions

File tree

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
#include <odroid_go.h>
2+
#include "sensors/Adafruit_TCS34725.h"
3+
4+
//- #define CALI_ENABLE
5+
//- #define PROCESSING_ENABLE
6+
#define LCD_ENABLE
7+
8+
#if defined(PROCESSING_ENABLE)
9+
#undef LCD_ENABLE
10+
#endif
11+
12+
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X);
13+
14+
unsigned long preMillis = 0;
15+
unsigned long curMillis = 0;
16+
int rCal, gCal, bCal;
17+
uint16_t clear, red, green, blue;
18+
unsigned char step = 0;
19+
int cali(void);
20+
21+
int cali(void) {
22+
23+
uint32_t sum;
24+
float r, g, b;
25+
26+
switch (step) {
27+
28+
case 0:
29+
30+
curMillis = millis();
31+
if (curMillis - preMillis >= 5000) {
32+
33+
step = 1;
34+
35+
tcs.setInterrupt(false); // turn on LED
36+
tcs.getRawData(&red, &green, &blue, &clear);
37+
tcs.setInterrupt(true); // turn off LED
38+
39+
GO.lcd.clearDisplay();
40+
GO.lcd.setCursor(30, 50);
41+
GO.lcd.println("Put on GREEN");
42+
43+
sum = clear;
44+
r = red; r /= sum;
45+
g = green; g /= sum;
46+
b = blue; b /= sum;
47+
r *= 256; g *= 256; b *= 256;
48+
49+
rCal = r;
50+
51+
preMillis = millis();
52+
}
53+
break;
54+
55+
case 1:
56+
57+
curMillis = millis();
58+
if (curMillis - preMillis >= 5000) {
59+
60+
step = 2;
61+
62+
tcs.setInterrupt(false); // turn on LED
63+
//- delay(60); // takes 50ms to read
64+
tcs.getRawData(&red, &green, &blue, &clear);
65+
tcs.setInterrupt(true); // turn off LED
66+
67+
GO.lcd.clearDisplay();
68+
GO.lcd.setCursor(30, 50);
69+
GO.lcd.println("Put on BLUE");
70+
71+
sum = clear;
72+
r = red; r /= sum;
73+
g = green; g /= sum;
74+
b = blue; b /= sum;
75+
r *= 256; g *= 256; b *= 256;
76+
77+
gCal = g;
78+
79+
preMillis = millis();
80+
}
81+
break;
82+
83+
case 2:
84+
85+
curMillis = millis();
86+
if (curMillis - preMillis >= 5000) {
87+
step = 3;
88+
89+
tcs.setInterrupt(false); // turn on LED
90+
tcs.getRawData(&red, &green, &blue, &clear);
91+
tcs.setInterrupt(true); // turn off LED
92+
93+
sum = clear;
94+
r = red; r /= sum;
95+
g = green; g /= sum;
96+
b = blue; b /= sum;
97+
r *= 256; g *= 256; b *= 256;
98+
99+
GO.lcd.clearDisplay();
100+
101+
bCal = b;
102+
}
103+
break;
104+
105+
case 3:
106+
107+
return 0;
108+
109+
default:;
110+
}
111+
112+
return 1;
113+
}
114+
115+
void setup() {
116+
GO.begin();
117+
Serial.println("Color View Test!");
118+
119+
if (tcs.begin()) {
120+
Serial.println("Found sensor");
121+
} else {
122+
Serial.println("No TCS34725 found ... check your connections");
123+
while (1); // halt!
124+
}
125+
126+
GO.lcd.setCursor(30, 50);
127+
GO.lcd.setTextSize(2);
128+
GO.lcd.println("Hello, ODROID-GO");
129+
130+
#if defined(CALI_ENABLE)
131+
delay(1000);
132+
133+
GO.lcd.clearDisplay();
134+
GO.lcd.setCursor(30, 50);
135+
GO.lcd.print("Put on RED");
136+
preMillis = millis();
137+
138+
while (cali());
139+
140+
GO.lcd.clearDisplay();
141+
GO.lcd.setTextColor(WHITE);
142+
GO.lcd.setCursor(0, 40);
143+
GO.lcd.setTextSize(2);
144+
GO.lcd.print("Cali:R("); GO.lcd.print(int(rCal), DEC);
145+
GO.lcd.print(") G("); GO.lcd.print(gCal, DEC);
146+
GO.lcd.print(") B("); GO.lcd.print(bCal, DEC);
147+
GO.lcd.println(")");
148+
#endif
149+
150+
delay(2000);
151+
}
152+
153+
void loop() {
154+
155+
//- uint16_t clear, red, green, blue;
156+
157+
tcs.setInterrupt(false); // turn on LED
158+
//- delay(60); // takes 50ms to read
159+
tcs.getRawData(&red, &green, &blue, &clear);
160+
tcs.setInterrupt(true); // turn off LED
161+
162+
#if !defined(LCD_ENABLE)
163+
Serial.print("C:\t"); Serial.print(clear);
164+
Serial.print("\tR:\t"); Serial.print(red);
165+
Serial.print("\tG:\t"); Serial.print(green);
166+
Serial.print("\tB:\t"); Serial.print(blue);
167+
#endif
168+
169+
// Figure out some basic hex code for visualization
170+
uint32_t sum = clear;
171+
float r, g, b;
172+
r = red; r /= sum;
173+
g = green; g /= sum;
174+
b = blue; b /= sum;
175+
r *= 256; g *= 256; b *= 256;
176+
177+
#if defined(CALI_ENABLE)
178+
r = r - rCal + 256;
179+
g = g - gCal + 256;
180+
b = b - bCal + 256;
181+
#endif
182+
183+
#if !defined(LCD_ENABLE)
184+
Serial.print("\t");
185+
Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);
186+
Serial.println();
187+
#endif
188+
189+
//Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" "); Serial.println((int)b );
190+
191+
#if defined(LCD_ENABLE)
192+
193+
uint16_t colorTemp, lux, rgb565;
194+
195+
colorTemp = tcs.calculateColorTemperature(r, g, b);
196+
lux = tcs.calculateLux(r, g, b);
197+
rgb565 = (((int)r) & 0xF8) << 8 | (((int)g) & 0xFC) << 3 | ((int)b) >> 3;
198+
199+
//- GO.lcd.clearDisplay();
200+
GO.lcd.fillScreen(rgb565);
201+
GO.lcd.setTextColor(WHITE);
202+
GO.lcd.setCursor(0, 40);
203+
GO.lcd.setTextSize(2);
204+
GO.lcd.print("* RGB565(Hex) : 0x");
205+
GO.lcd.println(rgb565, HEX);
206+
GO.lcd.println(" ");
207+
208+
GO.lcd.print("* Color Temp : "); GO.lcd.println(colorTemp, DEC);
209+
GO.lcd.print("* Lux : "); GO.lcd.println(lux, DEC);
210+
GO.lcd.println(" ");
211+
212+
GO.lcd.print("* R - raw : "); GO.lcd.print(int(r), DEC); GO.lcd.print(" - "); GO.lcd.println(red, DEC);
213+
GO.lcd.print("* G - raw : "); GO.lcd.print(int(g), DEC); GO.lcd.print(" - "); GO.lcd.println(green, DEC);
214+
GO.lcd.print("* B - raw : "); GO.lcd.print(int(b), DEC); GO.lcd.print(" - "); GO.lcd.println(blue, DEC);
215+
GO.lcd.print("* Clear : "); GO.lcd.print(int(clear), DEC);
216+
217+
delay(1000);
218+
219+
#endif
220+
}
221+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <odroid_go.h>
2+
#include "sensors/ir/IRremote.h"
3+
4+
const int RECV_PIN = 4;
5+
6+
IRrecv irrecv(RECV_PIN);
7+
decode_results results;
8+
9+
void setup() {
10+
// put your setup code here, to run once:
11+
GO.begin();
12+
13+
GO.lcd.setTextDatum(MC_DATUM);
14+
GO.lcd.setTextFont(4);
15+
GO.lcd.setTextSize(1);
16+
GO.lcd.setTextColor(WHITE);
17+
GO.lcd.drawString("====== IR Receiver Test ======", 120, 0);
18+
19+
Serial.println("Enabling IRin");
20+
irrecv.enableIRIn(); // Start the receiver
21+
Serial.println("Enabled IRin");
22+
23+
GO.lcd.setTextSize(2);
24+
GO.lcd.setTextColor(RED);
25+
displayStatusUpdate("NO SIGNAL");
26+
}
27+
28+
void decodeSignal() {
29+
GO.lcd.setTextColor(GREEN);
30+
switch (results.value) {
31+
case 0x4DB23BC4:
32+
displayStatusUpdate("POWER");
33+
break;
34+
case 0x4DB211EE:
35+
displayStatusUpdate("MUTE");
36+
break;
37+
case 0x4DB241BE:
38+
displayStatusUpdate("HOME");
39+
break;
40+
case 0x4DB2738C:
41+
displayStatusUpdate("OK");
42+
break;
43+
case 0x4DB253AC:
44+
displayStatusUpdate("UP");
45+
break;
46+
case 0x4DB29966:
47+
displayStatusUpdate("LEFT");
48+
break;
49+
case 0x4DB2837C:
50+
displayStatusUpdate("RIGHT");
51+
break;
52+
case 0x4DB24BB4:
53+
displayStatusUpdate("DOWN");
54+
break;
55+
case 0x4DB2A35C:
56+
displayStatusUpdate("MENU");
57+
break;
58+
case 0x4DB259A6:
59+
displayStatusUpdate("BACK");
60+
break;
61+
case 0x4DB2817E:
62+
displayStatusUpdate("VOL DOWN");
63+
break;
64+
case 0x4DB201FE:
65+
displayStatusUpdate("VOL UP");
66+
break;
67+
case 0xFFFFFFFF:
68+
GO.lcd.setTextColor(BLUE);
69+
displayStatusUpdate("REFEATED");
70+
break;
71+
case 0x4DB2:
72+
GO.lcd.setTextColor(RED);
73+
displayStatusUpdate("BROKEN");
74+
break;
75+
default:
76+
GO.lcd.setTextColor(RED);
77+
displayStatusUpdate("UNKNOWN");
78+
break;
79+
}
80+
}
81+
82+
void displayStatusUpdate(String result) {
83+
GO.lcd.fillRect(0, 92, 320, 48, BLACK);
84+
GO.lcd.drawString(result, 160, 122);
85+
}
86+
87+
void loop() {
88+
// put your main code here, to run repeatedly:
89+
if (irrecv.decode(&results)) {
90+
Serial.print("received: ");
91+
Serial.println(results.value, HEX);
92+
93+
decodeSignal();
94+
irrecv.resume(); // Receive the next value
95+
}
96+
delay(100);
97+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <odroid_go.h>
2+
3+
#define PIN_BLUE_LED 2
4+
#define PIN_PIR_INPUT 4
5+
6+
int prePirValue;
7+
int pirValue;
8+
9+
void setup() {
10+
// put your setup code here, to run once:
11+
GO.begin();
12+
13+
GO.lcd.setTextFont(4);
14+
GO.lcd.setTextSize(1);
15+
GO.lcd.setTextColor(WHITE);
16+
GO.lcd.setCursor(0, 0);
17+
GO.lcd.print("= PIR Motion Detector Test =");
18+
19+
pinMode(PIN_BLUE_LED, OUTPUT);
20+
pinMode(PIN_PIR_INPUT, INPUT);
21+
digitalWrite(PIN_BLUE_LED, LOW);
22+
23+
displayStatusUpdate();
24+
}
25+
26+
void displayStatusUpdate() {
27+
GO.lcd.fillRect(0, 100, 320, 48, BLACK);
28+
GO.lcd.setTextSize(2);
29+
30+
if (pirValue) {
31+
GO.lcd.setTextColor(GREEN);
32+
GO.lcd.setCursor(58, 100);
33+
GO.lcd.print("Detected");
34+
} else {
35+
GO.lcd.setTextColor(RED);
36+
GO.lcd.setCursor(16, 100);
37+
GO.lcd.print("Not Detected");
38+
}
39+
}
40+
41+
void loop() {
42+
// put your main code here, to run repeatedly:
43+
pirValue = digitalRead(PIN_PIR_INPUT);
44+
if (prePirValue != pirValue) {
45+
displayStatusUpdate();
46+
prePirValue = pirValue;
47+
}
48+
49+
digitalWrite(PIN_BLUE_LED, pirValue);
50+
}

0 commit comments

Comments
 (0)