mirror of
https://github.com/Lemonochrme/clover.git
synced 2025-06-08 16:50:50 +02:00
Added U8g2lib. Created Component base class for Analog and Digital. Created Display class and displaying "Hello World!".
This commit is contained in:
parent
af7a553111
commit
8dc600fc90
7 changed files with 95 additions and 16 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"string": "cpp"
|
||||
}
|
||||
},
|
||||
"cmake.configureOnOpen": false
|
||||
}
|
27
lib/Component/Component.cpp
Normal file
27
lib/Component/Component.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "Component.hpp"
|
||||
|
||||
Component::Component(ComponentType ct, uint8_t p)
|
||||
: _type(ct), _pin(p)
|
||||
{}
|
||||
|
||||
std::any Component::getValue(void){
|
||||
switch(_type)
|
||||
{
|
||||
case ComponentType::Digital:
|
||||
return digitalRead(_pin);
|
||||
case ComponentType::Analog:
|
||||
return analogRead(_pin);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Component::sendValue(std::any data)
|
||||
{
|
||||
switch(_type) {
|
||||
case ComponentType::Digital:
|
||||
digitalWrite(_pin, std::any_cast<uint8_t>(data));
|
||||
case ComponentType::Analog:
|
||||
analogWrite(_pin, std::any_cast<int>(data));
|
||||
}
|
||||
}
|
23
lib/Component/Component.hpp
Normal file
23
lib/Component/Component.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef _HEADER_COMPONENT
|
||||
#define _HEADER_COMPONENT
|
||||
#include <Arduino.h>
|
||||
#include <any>
|
||||
|
||||
enum class ComponentType {
|
||||
Digital,
|
||||
Analog,
|
||||
I2C,
|
||||
Serial
|
||||
};
|
||||
|
||||
class Component{
|
||||
public:
|
||||
Component(ComponentType ct, uint8_t p);
|
||||
std::any getValue();
|
||||
void sendValue(std::any data);
|
||||
private:
|
||||
ComponentType _type;
|
||||
const uint8_t _pin;
|
||||
};
|
||||
|
||||
#endif //_HEADER_COMPONENT
|
16
lib/Component/Display.cpp
Normal file
16
lib/Component/Display.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "Display.hpp"
|
||||
|
||||
Display::Display()
|
||||
{
|
||||
_display = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0,U8X8_PIN_NONE,SCL,SDA);
|
||||
_display->begin();
|
||||
}
|
||||
|
||||
void Display::loop()
|
||||
{
|
||||
_display->clearBuffer(); // clear the internal memory
|
||||
_display->setFont(u8g2_font_ncenB08_tr); // choose a suitable font
|
||||
_display->drawStr(0,10,"Hello World!"); // write something to the internal memory
|
||||
_display->sendBuffer(); // transfer internal memory to the display
|
||||
delay(1000);
|
||||
}
|
10
lib/Component/Display.hpp
Normal file
10
lib/Component/Display.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <U8g2lib.h>
|
||||
#include <Wire.h>
|
||||
|
||||
class Display {
|
||||
public:
|
||||
Display();
|
||||
void loop();
|
||||
private:
|
||||
U8G2_SSD1306_128X64_NONAME_F_HW_I2C* _display;
|
||||
};
|
|
@ -12,6 +12,8 @@
|
|||
platform = espressif8266
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
lib_deps = tzapu/WiFiManager@^0.16.0
|
||||
lib_deps =
|
||||
tzapu/WiFiManager@^0.16.0
|
||||
bbx10/DNSServer@^1.1.0
|
||||
ArduinoJson
|
||||
olikraus/U8g2@^2.35.7
|
||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -4,27 +4,27 @@
|
|||
|
||||
#include "ServerHandler.hpp"
|
||||
#include "DataHandler.hpp"
|
||||
#include "Component.hpp"
|
||||
#include "Display.hpp"
|
||||
|
||||
DataHandler dataHandler;
|
||||
ServerHandler serverHandler(&dataHandler); // Référence à dataHandler
|
||||
Component humidity(ComponentType::Analog, PIN_A0);
|
||||
Display screen;
|
||||
|
||||
|
||||
void setup() {
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
dataHandler.updateTemperatureData(20.0);
|
||||
dataHandler.updateHumidityData(3.141592);
|
||||
|
||||
serverHandler.setup("Redmi Note 10", "bbooksdd");
|
||||
serverHandler.setup("Iphone de Nicole", "cesthonteux");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println(dataHandler.getJsonData());
|
||||
|
||||
void loop()
|
||||
{
|
||||
screen.loop();
|
||||
dataHandler.updateTemperatureData(random(1800, 2200) / 100.0);
|
||||
dataHandler.updateHumidityData(random(4400, 5000)/100.0);
|
||||
dataHandler.updateHumidityData(static_cast<float>(std::any_cast<int>(humidity.getValue())));
|
||||
Serial.println(dataHandler.getJsonData());
|
||||
delay(1000);
|
||||
|
||||
|
||||
serverHandler.loop();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue