Compare commits

...

3 Commits

Author SHA1 Message Date
b0c90360b8 feat: use oled screen lib 2023-05-14 09:06:08 +02:00
f2bd530d4e feat: add config and oled screen lib 2023-05-14 09:05:57 +02:00
d814d16733 feat: add oled screen lib 2023-05-14 09:05:23 +02:00
6 changed files with 155 additions and 0 deletions

View File

@ -14,6 +14,14 @@ build_flags =
-D MONITOR_SPEED=${config.monitor_speed}
; DO NOT TOUCH --- END
; taille ecran oled
; 3,3v
-D OLED_WIDTH=128
-D OLED_HEIGHT=64
; pin de reset de l'ecran oled
-D OLED_RESET=-1
; DHT pin and type
; 5v
-D DHTTYPE=\"DHT11\"
@ -25,6 +33,7 @@ build_flags =
-D ULTRA_SOUND_ECHO=13
; Capteur poids
; 3,3v
-D POID_DOUT=14
-D POID_SCK=15

View File

@ -10,6 +10,7 @@
#include "Ultrason.h"
#include "HumiTemp.h"
#include "Balance.h"
#include "OledScreen.h"
class Program{
public:
@ -46,6 +47,12 @@ private:
*/
Capteur *balance;
/**
* @brief OledScreen
*
*/
OledScreen* screen;
/**
* @brief Réference de l'API pour les calls
*

View File

@ -0,0 +1,53 @@
#ifndef OLED_SCREEN_H
#define OLED_SCREEN_H
#include <Adafruit_SSD1306.h>
class OledScreen {
public:
/**
* @brief Construct a new Oled Screen object
*
* @param screenWidth The width of the screen
* @param screenHeight The height of the screen
* @param oledResetPin The pin used to reset the screen (default: -1)
*/
OledScreen(int screenWidth, int screenHeight, int oledResetPin = -1);
/**
* @brief display welcome screen
*/
void welcome();
/**
* @brief print the total amount on the screen
*
* @param amount The total amount to print in centimes
*/
void printAmount(int amount);
/**
* @brief Clear the screen
*/
void clear();
/**
* @brief messsage for wifi waiting
*
*/
void wifiWaiting();
void printVal(String distance, String poid, String humitemp);
private:
Adafruit_SSD1306* display;
};
#endif

View File

@ -0,0 +1,76 @@
#include "../include/OledScreen.h"
OledScreen::OledScreen(int screenWidth, int screenHeight, int oledResetPin) {
this->display = new Adafruit_SSD1306(screenWidth, screenHeight, &Wire, oledResetPin);
if (!display->begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
this->display->clearDisplay();
}
void OledScreen::welcome() {
this->display->clearDisplay();
this->display->setCursor(0, 0);
this->display->setTextSize(2);
this->display->setTextColor(WHITE);
this->display->println(F("\nBienvenue!"));
this->display->display();
}
void OledScreen::printVal(String distance, String poid, String humitemp){
this->display->clearDisplay();
this->display->setCursor(0, 0);
this->display->setTextSize(2);
this->display->setTextColor(WHITE);
this->display->print(F("Dist:"));
this->display->print(distance);
this->display->println();
this->display->print(F("Poids:"));
this->display->print(poid);
this->display->println();
this->display->print(F("humi:"));
this->display->print(humitemp.substring(0,humitemp.indexOf("/")));
this->display->println();
this->display->print(F("temp:"));
this->display->print(humitemp.substring(humitemp.indexOf("/")+1,humitemp.length()));
this->display->println();
this->display->display();
}
void OledScreen::printAmount(int amount) {
this->display->clearDisplay();
this->display->setCursor(0, 0);
this->display->setTextSize(2);
this->display->setTextColor(WHITE);
this->display->println(F(" Total: "));
this->display->println();
this->display->print(amount / 100);
this->display->print(F(","));
int centimes = amount % 100;
if (centimes < 10) {
this->display->print(F("0"));
}
this->display->println(centimes);
this->display->print(F(" EUR"));
this->display->display();
}
void OledScreen::wifiWaiting() {
this->clear();
this->display->setCursor(0, 0);
this->display->setTextSize(2);
this->display->setTextColor(WHITE);
this->display->println(F("Connection\n"));
this->display->println(F(" WiFi...\n"));
this->display->println();
this->display->display();
}
void OledScreen::clear() {
this->display->clearDisplay();
}

View File

@ -42,6 +42,7 @@ lib_deps =
adafruit/Adafruit Unified Sensor@^1.1.9 ; adafruit sensor lib (required by DHT11)
ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son
bogde/HX711@0.7.5 ; lib pour la balance
adafruit/Adafruit SSD1306@^2.5.7 ; librairie pour l'ecran oled
; example:
; erropix/ESP32 AnalogWrite@^0.2

View File

@ -6,6 +6,10 @@ Program::Program(){
Serial1.begin(MONITOR_SPEED);
Serial.begin(MONITOR_SPEED);
//////Oled Screen/////
this->screen = new OledScreen(OLED_WIDTH, OLED_HEIGHT, OLED_RESET);
this->screen->wifiWaiting();
////////API///////
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
@ -16,6 +20,8 @@ Program::Program(){
this->dht = new HumiTemp(DHTPIN, DHTTYPE, DHT_FULL);
this->balance = new Balance(POID_DOUT,POID_SCK, POID_FULL);
this->balance->tar(1077);
this->screen->clear();
}
void Program::loop(){
@ -23,6 +29,9 @@ void Program::loop(){
String humitemp = this->dht->read();
String poid = this->balance->read();
this->screen->printVal(distance, poid, humitemp);
this->api->sendValue(distance, TRASHCAN_ONE, this->ultrasonic->getValType(), this->ultrasonic->isFull());
Serial.print("Distance in CM = " + distance);
Serial.println(this->ultrasonic->isFull()?" true":" false");