-
Notifications
You must be signed in to change notification settings - Fork 0
/
fireflyFlora.ino
108 lines (94 loc) · 2.52 KB
/
fireflyFlora.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include <avr/io.h>
#include <util/delay.h>
#define BLINK_DELAY_MS 2
/* Example code for the Adafruit TCS34725 breakout library */
/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */
/* Initialise with default values (int time = 2.4ms, gain = 60x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_60X);
int poo = 1;
int lastPoo = 1;
int counter1 = 1;
int counter2 = 1;
long y,z,w,a,us;
int x = 1;
uint16_t lastLux = 1;
uint16_t butt = 1;
//uint16_t lux = 1;
void setup(void) {
Serial.begin(115200);
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
// Now we're ready to get readings!
}
void loop (void) {
//shine();
sense();
if (x<250)sense();
else shine();
//lux();
}
void shine (void) {
counter2 +=1;
if (counter2 <500) {
bloop();
shine();
}
else {counter2 = 0; x = 0;
counter1=0;}
}
void sense (void) {
us = micros();
lastLux = butt;
lastPoo=poo;
if (us%4000 >= 3950) lux();
else sense();
if (lux > lastLux) poo = 1;
else poo = 0;
if (poo != lastPoo) counter1+=1;
else counter1=0;
if (counter1==16) x *= 1.1;
}
void lux() {
tcs.setInterrupt(true);
uint16_t r, g, b, c, lux, colorTemp;
//Serial.print(lux);
tcs.getRawData(&r, &g, &b, &c);
// colorTemp = tcs.calculateColorTemperature(r, g, b);
//colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
lux = tcs.calculateLux(r, g, b);
x += 1;
butt=lux;
//Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
Serial.print(x);
Serial.print(" ");
Serial.print(counter1);
//Serial.print("poo: "); Serial.print(x, DEC); Serial.print(" - ");
//Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
//Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
//Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
//Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
}
int bloop (void){
/* set pin 5 of PORTB for output*/
DDRB |= _BV(DDB5);
//while(1) {
/* set pin 5 high to turn led on */
PORTB |= _BV(PORTB3);
_delay_ms(BLINK_DELAY_MS);
/* set pin 5 low to turn led off */
PORTB &= ~_BV(PORTB3);
_delay_ms(BLINK_DELAY_MS);
//}
}