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 # 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. Temps réglable (MM:SS), boutons poussoirs ou encodeur rotatif, mini afficheur oled.
Utilisation d'un encodeur rotatif, d'un mini afficheur oled et d'un module relais.
# Environnement ## Schéma de principe
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
![principe](./doc/schema_principe.jpg) ![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 ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[env:d1_mini_lite] [env:esp32cam]
platform = espressif8266 platform = espressif32
board = d1_mini_lite board = esp32cam
upload_protocol = esptool
framework = arduino framework = arduino
lib_deps = lib_deps =
adafruit/Adafruit SSD1306@^2.5.7 adafruit/Adafruit SSD1306@^2.5.7

View File

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