-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
115 lines (90 loc) · 3.36 KB
/
Copy pathmain.cpp
File metadata and controls
115 lines (90 loc) · 3.36 KB
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
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/binary_info.h"
#include "hardware/i2c.h"
#include "includes/AS7341.h"
AS7341 sensorOne;
AS7341 sensorTwo;
int main() {
stdio_init_all();
printf("Starting\n");
if (!sensorOne.begin(i2c0)){
printf("Could not find AS7341\n");
while (1) { sleep_ms(10); }
}
if (!sensorTwo.begin(i2c1)){
printf("Could not find AS7341\n");
while (1) { sleep_ms(10); }
}
printf("Testing Sensor\n");
printf("Sensor OK\n");
printf("Ready\n");
sensorOne.setATIME(29);
sensorOne.setASTEP(599);
sensorOne.setGain(AS7341_GAIN_0_5X);
sensorTwo.setATIME(29);
sensorTwo.setASTEP(599);
sensorTwo.setGain(AS7341_GAIN_0_5X);
sensorOne.enableSpectralMeasurement(true);
sensorTwo.enableSpectralMeasurement(true);
sensorOne.setLEDCurrent(4);
sensorOne.enableLED(true);
sensorTwo.setLEDCurrent(4);
sensorTwo.enableLED(true);
while(true){
printf("Getting Readings\n");
// put your main code here, to run repeatedly:
uint16_t readings[12];
float counts[12];
uint16_t readings2[12];
float counts2[12];
sensorOne.setLEDCurrent(4);
sensorOne.enableLED(true);
if (!sensorOne.readAllChannels(readings)){
printf("Error reading all channels!");
return false;
}
for(uint8_t i = 0; i < 12; i++) {
if(i == 4 || i == 5) continue;
// we skip the first set of duplicate clear/NIR readings
// (indices 4 and 5)
counts[i] = sensorOne.toBasicCounts(readings[i]);
}
printf("Sensor1 - F1 415nm : %f\n", counts[0]);
printf("Sensor1 - F2 445nm : %f\n", counts[1]);
printf("Sensor1 - F3 480nm : %f\n", counts[2]);
printf("Sensor1 - F4 515nm : %f\n", counts[3]);
printf("Sensor1 - F5 555nm : %f\n", counts[6]);
printf("Sensor1 - F6 590nm : %f\n", counts[7]);
printf("Sensor1 - F7 630nm : %f\n", counts[8]);
printf("Sensor1 - F8 680nm : %f\n", counts[9]);
printf("Sensor1 - Clear : %f\n", counts[10]);
printf("Sensor1 - NIR : %f\n", counts[11]);
printf("Readings Done\n");
sensorOne.enableLED(false);
sensorTwo.setLEDCurrent(4);
sensorTwo.enableLED(true);
if (!sensorTwo.readAllChannels(readings2)){
printf("Error reading all channels!");
return false;
}
for(uint8_t i = 0; i < 12; i++) {
if(i == 4 || i == 5) continue;
// we skip the first set of duplicate clear/NIR readings
// (indices 4 and 5)
counts2[i] = sensorTwo.toBasicCounts(readings2[i]);
}
printf("Sensor2 - F1 415nm : %f\n", counts2[0]);
printf("Sensor2 - F2 445nm : %f\n", counts2[1]);
printf("Sensor2 - F3 480nm : %f\n", counts2[2]);
printf("Sensor2 - F4 515nm : %f\n", counts2[3]);
printf("Sensor2 - F5 555nm : %f\n", counts2[6]);
printf("Sensor2 - F6 590nm : %f\n", counts2[7]);
printf("Sensor2 - F7 630nm : %f\n", counts2[8]);
printf("Sensor2 - F8 680nm : %f\n", counts2[9]);
printf("Sensor2 - Clear : %f\n", counts2[10]);
printf("Sensor2 - NIR : %f\n", counts2[11]);
printf("Readings Done\n");
sensorTwo.enableLED(false);
}
}