Compare commits

..

No commits in common. "bc904d4f01b5daa52656625f9fe9694a98458a3a" and "04da921dc7b61f8db057ec68bf2ece904ba904a8" have entirely different histories.

4 changed files with 28 additions and 58 deletions

View File

@ -1,17 +1,7 @@
# Minuteur
Basé sur un ESP8266 D1 Mini Wemos, pour interrompre une alimentation USB (via transistor ou relais ?).
Basé sur un ESP32-CAM, pour interrompre une alimentation USB (via transistor ou relais ?).
Temps réglable en secondes.
Utilisation d'un encodeur rotatif, d'un mini afficheur oled et d'un module relais.
Temps réglable (MM:SS), boutons poussoirs ou encodeur rotatif, mini afficheur oled.
# Environnement
VSCodium et PlatformIO
## Librairies utilisées
adafruit/Adafruit SSD1306@^2.5.7
adafruit/Adafruit GFX Library@^1.11.7
mathertel/RotaryEncoder@^1.5.3
*Voir le fichier platformio.ini pour les dernières mise à jour.*
## Schéma
## Schéma de principe
![principe](./doc/schema_principe.jpg)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 128 KiB

View File

@ -8,10 +8,9 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:d1_mini_lite]
platform = espressif8266
board = d1_mini_lite
upload_protocol = esptool
[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
lib_deps =
adafruit/Adafruit SSD1306@^2.5.7

View File

@ -4,7 +4,6 @@
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RotaryEncoder.h>
#include <EEPROM.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
@ -15,22 +14,25 @@
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//#define SDA 4
//#define SCL 5
#define SDA 12
#define SCL 13
#define SORTIE_RELAIS 16
#define ENCROT_A 12
#define ENCROT_B 13
#define ENCROT_BP 14
#define LED_FLASH 4
#define LED_BUILTIN 33
#define ENCROT_A 14
#define ENCROT_B 15
#define ENCROT_BP 2
// Setup a RotaryEncoder with 2 steps per latch for the 2 signal input pins:
RotaryEncoder encoder(ENCROT_A, ENCROT_B, RotaryEncoder::LatchMode::TWO03);
// durée par défaut en secondes
int count;
bool statutDecompte = 0;
unsigned long LastUpdateTimer = 0;
int count = 12;
bool decompteStatut = false;
unsigned long LastUpdate = 0;
unsigned long LastReadBP = 0;
#define LOGO_HEIGHT 32
@ -55,11 +57,6 @@ void setup() {
pinMode(SORTIE_RELAIS, OUTPUT);
digitalWrite(SORTIE_RELAIS, LOW);
//Init EEPROM
EEPROM.begin(1);
EEPROM.get(0, count);
//Init I2C
Wire.begin(SDA, SCL); // join i2c bus (address optional for master)
Serial.begin(115200); // start serial for output
@ -69,7 +66,6 @@ void setup() {
for(;;); // Don't proceed, loop forever
}
encoder.setPosition(count);
// Clear the buffer
display.clearDisplay();
@ -87,14 +83,13 @@ void loop() {
display.setTextSize(6);
display.setTextColor(SSD1306_WHITE); // Draw white text
unsigned long currentMillis = millis();
int newPos;
if (statutDecompte) { // on est en mode de compte à rebours
if (decompteStatut) {
if (count > 0) {
if (currentMillis - LastUpdateTimer >= 1000) {
LastUpdateTimer = currentMillis;
if (currentMillis - LastUpdate >= 1000) {
--count;
LastUpdate = currentMillis;
display.clearDisplay();
display.setCursor(0, 20);
display.println(count);
@ -102,20 +97,14 @@ void loop() {
}
}
else {
statutDecompte = 0;
count = encoder.getPosition();
display.clearDisplay();
display.setCursor(0, 20);
display.println(count);
display.display();
decompteStatut = 0;
}
}
else { // on est en mode réglage / pause
else {
static int pos = 0;
encoder.tick();
newPos = encoder.getPosition();
int newPos = encoder.getPosition();
if (pos != newPos) {
if (newPos < 0) {
newPos = 0;
@ -130,18 +119,10 @@ void loop() {
} // if
}
if (digitalRead(ENCROT_BP) && (currentMillis - LastReadBP > 250)){
if (!digitalRead(ENCROT_BP) && (LastReadBP - currentMillis > 250)){
LastReadBP = currentMillis;
statutDecompte = !statutDecompte;
if (statutDecompte) {
LastUpdateTimer = currentMillis;
EEPROM.put(0, count);
EEPROM.commit();
}
else {
encoder.setPosition(count);
}
decompteStatut = !decompteStatut;
}
digitalWrite(SORTIE_RELAIS, statutDecompte);
digitalWrite(SORTIE_RELAIS, decompteStatut);
}