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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
//***************************************/
// LOLIN (Wemos) D1 R2 & mini
// SCD40 I2C
// SH1107 128 x 128 I2C
//
// ------------
// | |
// | |
// | | D1 SCL
// | | D2 SDA
// | |
// | | D4 LEDS
// | --- | GND
// SCD40+3.3v | | | | + 5V
// ------------
//
//****************************************/
#include <SensirionI2CScd4x.h>
#include <U8g2lib.h>
#include "FastLED.h"
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#define NUM_LEDS 3
#define DATA_PIN 2
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
SensirionI2CScd4x scd40;
uint16_t co2 = 0;
float temperature = 0.0;
float humidity = 0.0;
U8G2_SH1107_SEEED_128X128_F_HW_I2C oled(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
CRGB leds[NUM_LEDS];
int value = 0;
int Mapping, Mapping0, Mapping1, Mapping2, Mapping3, Mapping4, Mapping5, Mapping6, Mapping7;
int frequency = 0;
int quantity=1;
/******************/
/* SETUP */
/******************/
void setup() {
Serial.begin(115200);
while (!Serial) { // Attente d'une connexion avec l'ordinateur
delay(100);
}
pinMode(DATA_PIN, OUTPUT);
LEDS.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
Mapping0 = Mapping1 = Mapping2 = Mapping3 = Mapping4 = Mapping5 = Mapping6 = Mapping7 = 123;
oled.begin();
oled.clearDisplay();
oled.setContrast(1);
scd40.begin(Wire);
scd40.stopPeriodicMeasurement();
scd40.startPeriodicMeasurement();
Serial.println("Waiting for measurement...");
// oled.clearBuffer();
oled.setFont(u8g2_font_siji_t_6x10);
oled.drawStr(0, 30, "Attendre");
oled.drawStr(0, 40, "Mesure....");
oled.sendBuffer();
}
/******************/
/* LOOP */
/******************/
void loop() {
led();
bool dataReady = false;
scd40.getDataReadyFlag(dataReady);
if (dataReady) {
scd40.readMeasurement(co2, temperature, humidity);
Serial.print("CO2:");
Serial.print(co2);
Serial.print(" ");
Serial.print("Temperature:");
Serial.print(temperature);
Serial.print(" ");
Serial.print("Humidite:");
Serial.println(humidity);
oled.clearBuffer();
oled.setFont(u8g2_font_8x13_tf);
oled.drawStr(0, 10, "CO");
oled.setFont(u8g2_font_siji_t_6x10);
oled.drawStr(16, 14, "2");
oled.setFont(u8g2_font_siji_t_6x10);
oled.drawStr(0, 22, "(ppm)");
String co2_string = String(co2);
oled.setFont(u8g2_font_courB24_tf);
int x_pos = (oled.getDisplayWidth() - oled.getStrWidth(co2_string.c_str()));
oled.setCursor(x_pos, 22);
oled.print(co2_string);
oled.setFontMode(1);
oled.setDrawColor(2);
oled.drawBox(0, 31, 60, 11);
oled.drawBox(70, 31, 60, 11);
oled.setFont(u8g2_font_6x12_t_symbols);
oled.drawGlyph(20, 41, 176);
oled.drawGlyph(26, 40, 67);
oled.drawStr(90, 40, "%");
oled.drawStr(100, 40, "RH");
oled.setFont(u8g2_font_8x13_tf);
oled.setCursor(10, 60);
oled.print(temperature, 1);
oled.setCursor(80, 60);
oled.print(humidity, 1);
oled.sendBuffer();
Mapping = map(co2, 400, 2000, 123, 70);
frequency = map(co2, 400, 2000, 50, 0);
//quantity = map(co2, 400, 2000, 1, 3);
quantity = 1;
Mapping7 = Mapping6;
Mapping6 = Mapping5;
Mapping5 = Mapping4;
Mapping4 = Mapping3;
Mapping3 = Mapping2;
Mapping2 = Mapping1;
Mapping1 = Mapping0;
Mapping0 = Mapping;
oled.setFont(u8g2_font_siji_t_6x10);
oled.setCursor(/*x=*/5, /*y=*/75);
oled.print("2K");
oled.setFontMode(1);
oled.setDrawColor(2);
oled.drawLine(2, 70, 2,125);
oled.setCursor(2, 105);
oled.setFont(u8g2_font_u8glib_4_tf);
oled.print("--"); // ligne pour 1000
oled.drawLine(2,125,123,125);
oled.sendBuffer();
oled.setFontMode(1);
oled.setDrawColor(2);
oled.drawLine(35, Mapping6, 10, Mapping7);
oled.drawLine(50, Mapping5, 35, Mapping6);
oled.drawLine(65, Mapping4, 50, Mapping5);
oled.drawLine(80, Mapping3,65, Mapping4);
oled.drawLine(95, Mapping2,80, Mapping);
oled.drawLine(110, Mapping1, 95, Mapping2);
oled.drawLine(123, Mapping0,110, Mapping1);
oled.sendBuffer();
}
}
void led() {
for (1; value < 50; value++) {
FastLED.setBrightness(value);
if (frequency > 35) {
fill_solid(leds, quantity, CRGB::Green);
} else {
fill_solid(leds, quantity, CRGB::Red);
}
FastLED.show();
Serial.println(value);
delay(frequency);
}
for (50; value > 1; value--) {
FastLED.setBrightness(value);
if (frequency > 35) {
fill_solid(leds, quantity, CRGB::Green);
} else {
fill_solid(leds, quantity, CRGB::Red);
}
FastLED.show();
Serial.println(value);
delay(frequency);
}
} |
Partager