Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
5b36dc4e
Commit
5b36dc4e
authored
Oct 23, 2021
by
Eric Duminil
Browse files
Binary clock
parent
fc87b9eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
5b36dc4e
...
...
@@ -15,22 +15,17 @@
// Required libraries:
// LED Ring:
#include "src/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h"
// CO2 sensor:
#include "src/lib/SparkFun_SCD30_Arduino_Library/src/SparkFun_SCD30_Arduino_Library.h"
#include <Wire.h>
// How many LEDs on the ring?
const
int
LED_COUNT
=
1
2
;
const
int
LED_COUNT
=
1
6
;
// Where is LED ring connected to micro-controller?
const
int
NEOPIXELS_PIN
=
5
;
// Define LED ring and CO2 sensor
Adafruit_NeoPixel
led_ring
(
LED_COUNT
,
NEOPIXELS_PIN
,
NEO_GRB
+
NEO_KHZ800
);
SCD30
sensor
;
// Define variables
int
which_led
;
uint16_t
co2
;
uint32_t
n
;
// The code in setup() will be run once, at startup.
void
setup
()
{
...
...
@@ -41,46 +36,26 @@ void setup() {
led_ring
.
begin
();
led_ring
.
setBrightness
(
255
);
// Initialize sensor (should be connected to D6 & D5), without auto-calibration.
Wire
.
begin
(
12
,
14
);
sensor
.
begin
(
false
);
// One measurement every 10s
sensor
.
setMeasurementInterval
(
10
);
}
// The code in loop() will be run as long as the micro-controller is powered up, in an infinite loop.
void
loop
()
{
if
(
sensor
.
dataAvailable
())
{
// New measurement is available. Let's display it!
co2
=
sensor
.
getCO2
();
Serial
.
print
(
"CO2 : "
);
Serial
.
print
(
co2
);
Serial
.
println
(
" ppm."
);
}
// Light the next LED
which_led
=
which_led
+
1
;
// Come back to first LED if needed.
if
(
which_led
>=
LED_COUNT
)
{
which_led
=
0
;
}
// First, disable every LED
led_ring
.
clear
();
// Check if air is good enough
if
(
co2
<=
1000
)
{
// Light the LED green if CO2 ppm is low
// position, red, green, blue
led_ring
.
setPixelColor
(
which_led
,
0
,
255
,
0
);
}
else
{
// Red otherwise.
// position, red, green, blue
led_ring
.
setPixelColor
(
which_led
,
255
,
0
,
0
);
for
(
int
i
=
0
;
i
<
LED_COUNT
;
++
i
)
{
if
((
n
>>
i
)
&
1
)
{
led_ring
.
setPixelColor
(
i
,
0
,
255
,
0
);
// led_ring.setPixelColor(i, led_ring.ColorHSV(i * 65535 / 16));
}
}
Serial
.
print
(
n
);
Serial
.
print
(
" = "
);
Serial
.
println
(
n
,
BIN
);
led_ring
.
show
();
n
=
n
+
1
;
// Wait half a second before next loop.
// Micro-controller might crash if it has too much work to do. Please don't remove it!
delay
(
5
00
);
delay
(
10
00
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment