#include "RTClib.h"
#include <Arduino.h> // required by platformIO
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <dht.h>
dht DHT;
#define DHTTYPE DHT22
#define DHT22_pin 5
float humidity;
float temperature;
RTC_DS1307 rtc;
// oled SSD1306 display connected to I2C
#define OLED_RESET 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
char datetimeBuffer[8] = "";
#define BP_Plus_PIN 2
#define BP_Moins_PIN 3
#define BP_Enter_PIN 4
boolean State_BP_Plus = HIGH;
boolean lastState_BP_Plus = HIGH;
boolean State_BP_Moins = HIGH;
boolean lastState_BP_Moins = HIGH;
boolean State_BP_Enter = HIGH;
boolean lastState_BP_Enter = HIGH;
int BP_Compt = 0;
void setup () {
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
pinMode(BP_Plus_PIN, INPUT_PULLUP);
pinMode(BP_Moins_PIN, INPUT_PULLUP);
pinMode(BP_Enter_PIN, INPUT_PULLUP);
}
void loop () {
//gestion BP +
State_BP_Plus = digitalRead(BP_Plus_PIN);
if (lastState_BP_Plus != State_BP_Plus && State_BP_Plus == LOW ) {
BP_Compt++;
}
Serial.print(" BP Compt PLUS 1 ");
Serial.println(BP_Compt);
lastState_BP_Plus = State_BP_Plus;
//gestion BP -
State_BP_Moins = digitalRead(BP_Moins_PIN);
if (lastState_BP_Moins != State_BP_Moins && State_BP_Moins == LOW) {
BP_Compt--;
}
lastState_BP_Moins = State_BP_Moins;
//gestion BP ENTER
State_BP_Enter = digitalRead(BP_Enter_PIN);
if (lastState_BP_Enter != State_BP_Enter) {
lastState_BP_Enter = State_BP_Enter;
if (State_BP_Enter == HIGH) {
//Serial.println(" BP Enter released");
}
if (State_BP_Enter == LOW) {
//Serial.println(" BP Enter pressed");
}
}
//heure();
temp();
hum();
refresh();
}
float temp() {
int chk = DHT.read22(5);
temperature = DHT.temperature;
return temperature;
}
float hum() {
int chk = DHT.read22(5);
humidity = DHT.humidity;
return humidity;
}
void heure() {
DateTime now = rtc.now();
sprintf(datetimeBuffer, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
// return datetimeBuffer;
}
void refresh() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("heure");
display.setCursor(70, 10);
display.println(datetimeBuffer);
display.setCursor(1, 30);
display.println("temperature");
display.setCursor(70, 30);
display.println(temperature);
display.setCursor(1, 50);
display.println("humidite");
display.setCursor(70, 50);
display.println(humidity);
display.display();
display.setCursor(100,40);
display.println(BP_Compt);
//Serial.print(datetimeBuffer);
//Serial.println();
delay(0);
}