-
Notifications
You must be signed in to change notification settings - Fork 0
/
od_sensor.ino
155 lines (130 loc) · 3.07 KB
/
od_sensor.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <Wire.h>
#include "SFE_ISL29125.h"
#include <SPI.h>
#include <SD.h>
bool OD_MESUREMENT = false;
bool verbose = true;
/*
* Relative to the TSL235r
*/
int tsl_input_pin = 2;
volatile unsigned long cnt = 0;
unsigned long oldcnt = 0;
unsigned long t = 0;
unsigned long last;
void irq1()
{
cnt++;
}
// Welcome attentive viewer, who paused the video to see what the code looks like!
//Great job...
/*
* Relative to the white LED
*/
int white_light_pin = 3;
/*
* Relative to the RGB light sensor
*/
SFE_ISL29125 RGB_sensor;
int red_low = 480;
int red_high = 3860;
int green_low = 770;
int green_high = 5950;
int blue_low = 575;
int blue_high = 4400;
/*
* Relative to the yellow LED
*/
int yellow_light_pin = 4;
/*
* Main
*/
int switch_cnt = 0;
int THRESHOLD = 10;
void switch_mode(){
switch_cnt = 0;
OD_MESUREMENT = !OD_MESUREMENT;
if (verbose){
Serial.println("SWITCH!");
}
if (OD_MESUREMENT){
if(verbose){
Serial.println("Start OD mesurement");
}
tsl_input_pin = 2;
cnt = 0;
oldcnt = 0;
t = 0;
last = millis();
digitalWrite(yellow_light_pin, LOW);
digitalWrite(white_light_pin, HIGH);
} else {
if(verbose){
Serial.print("Start fluorescence mesurement ");
Serial.println("(using yellow led approx 580 nm)");
}
digitalWrite(yellow_light_pin, HIGH);
digitalWrite(white_light_pin, LOW);
}
}
void setup() {
Serial.begin(9600);
//TSL235r setup
Serial.println("START");
pinMode(tsl_input_pin, INPUT);
digitalWrite(tsl_input_pin, HIGH);
attachInterrupt(0, irq1, RISING);
//Yellow LED setup
pinMode(yellow_light_pin, OUTPUT);
//White LED setup
pinMode(white_light_pin, OUTPUT);
//RGB light sensor setup
if (RGB_sensor.init()){
Serial.println("Sensor Initialization Successful\n\r");
}
switch_mode();
}
void od_mesurements(){
if (millis() - last >= 1000){
switch_cnt += 1;
last = millis();
t = cnt;
unsigned long hz = t - oldcnt;
Serial.print("FREQ: ");
Serial.print(hz);
Serial.print("\t = ");
Serial.print((hz+50)/100); // +50 == rounding last digit
Serial.println(" mW/m2");
oldcnt = t;
}
}
void fluo_mesurements(){
switch_cnt += 1;
unsigned int red = RGB_sensor.readRed();
unsigned int green = RGB_sensor.readGreen();
unsigned int blue = RGB_sensor.readBlue();
int redV = map(red, red_low, red_high, 0, 255);
int redVal = constrain(redV, 0, 255);
int greenV = map(green, green_low, green_high, 0, 255);
int greenVal = constrain(greenV, 0, 255);
int blueV = map(blue, blue_low, blue_high, 0, 255);
int blueVal = constrain(blueV, 0, 255);
Serial.print("Red: "); Serial.print(redVal);
Serial.print(", ");
Serial.print("Green: "); Serial.print(greenVal);
Serial.print(", ");
Serial.print("Blue: "); Serial.print(blueVal);
Serial.println();
}
void loop() {
if(switch_cnt == THRESHOLD){
switch_mode();
}
// put your main code here, to run repeatedly:
if (OD_MESUREMENT){
od_mesurements();
} else {
fluo_mesurements();
}
delay(2000);
}