Compare commits
5 Commits
04da921dc7
...
bc904d4f01
Author | SHA1 | Date | |
---|---|---|---|
bc904d4f01 | |||
8cd2ee3943 | |||
ecf8711e54 | |||
ffa4c5b006 | |||
dc76d0fad2 |
16
README.md
16
README.md
@ -1,7 +1,17 @@
|
|||||||
# Minuteur
|
# Minuteur
|
||||||
Basé sur un ESP32-CAM, pour interrompre une alimentation USB (via transistor ou relais ?).
|
Basé sur un ESP8266 D1 Mini Wemos, pour interrompre une alimentation USB (via transistor ou relais ?).
|
||||||
|
|
||||||
Temps réglable (MM:SS), boutons poussoirs ou encodeur rotatif, mini afficheur oled.
|
Temps réglable en secondes.
|
||||||
|
Utilisation d'un encodeur rotatif, d'un mini afficheur oled et d'un module relais.
|
||||||
|
|
||||||
## Schéma de principe
|
# 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
|
||||||

|

|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 179 KiB |
@ -8,9 +8,10 @@
|
|||||||
; 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:esp32cam]
|
[env:d1_mini_lite]
|
||||||
platform = espressif32
|
platform = espressif8266
|
||||||
board = esp32cam
|
board = d1_mini_lite
|
||||||
|
upload_protocol = esptool
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/Adafruit SSD1306@^2.5.7
|
adafruit/Adafruit SSD1306@^2.5.7
|
||||||
|
61
src/main.cpp
61
src/main.cpp
@ -4,6 +4,7 @@
|
|||||||
#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
|
||||||
@ -14,25 +15,22 @@
|
|||||||
#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 12
|
//#define SDA 4
|
||||||
#define SCL 13
|
//#define SCL 5
|
||||||
|
|
||||||
#define SORTIE_RELAIS 16
|
#define SORTIE_RELAIS 16
|
||||||
#define LED_FLASH 4
|
#define ENCROT_A 12
|
||||||
#define LED_BUILTIN 33
|
#define ENCROT_B 13
|
||||||
|
#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 = 12;
|
int count;
|
||||||
bool decompteStatut = false;
|
bool statutDecompte = 0;
|
||||||
unsigned long LastUpdate = 0;
|
unsigned long LastUpdateTimer = 0;
|
||||||
unsigned long LastReadBP = 0;
|
unsigned long LastReadBP = 0;
|
||||||
|
|
||||||
#define LOGO_HEIGHT 32
|
#define LOGO_HEIGHT 32
|
||||||
@ -57,6 +55,11 @@ 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
|
||||||
|
|
||||||
@ -66,6 +69,7 @@ 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();
|
||||||
|
|
||||||
@ -83,13 +87,14 @@ 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 (decompteStatut) {
|
if (statutDecompte) { // on est en mode de compte à rebours
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (currentMillis - LastUpdate >= 1000) {
|
if (currentMillis - LastUpdateTimer >= 1000) {
|
||||||
--count;
|
LastUpdateTimer = currentMillis;
|
||||||
LastUpdate = currentMillis;
|
|
||||||
|
|
||||||
|
--count;
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 20);
|
display.setCursor(0, 20);
|
||||||
display.println(count);
|
display.println(count);
|
||||||
@ -97,14 +102,20 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
decompteStatut = 0;
|
statutDecompte = 0;
|
||||||
|
count = encoder.getPosition();
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println(count);
|
||||||
|
display.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else { // on est en mode réglage / pause
|
||||||
static int pos = 0;
|
static int pos = 0;
|
||||||
encoder.tick();
|
encoder.tick();
|
||||||
|
|
||||||
int newPos = encoder.getPosition();
|
newPos = encoder.getPosition();
|
||||||
if (pos != newPos) {
|
if (pos != newPos) {
|
||||||
if (newPos < 0) {
|
if (newPos < 0) {
|
||||||
newPos = 0;
|
newPos = 0;
|
||||||
@ -119,10 +130,18 @@ void loop() {
|
|||||||
} // if
|
} // if
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!digitalRead(ENCROT_BP) && (LastReadBP - currentMillis > 250)){
|
if (digitalRead(ENCROT_BP) && (currentMillis - LastReadBP > 250)){
|
||||||
LastReadBP = currentMillis;
|
LastReadBP = currentMillis;
|
||||||
decompteStatut = !decompteStatut;
|
statutDecompte = !statutDecompte;
|
||||||
|
if (statutDecompte) {
|
||||||
|
LastUpdateTimer = currentMillis;
|
||||||
|
EEPROM.put(0, count);
|
||||||
|
EEPROM.commit();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
encoder.setPosition(count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(SORTIE_RELAIS, decompteStatut);
|
digitalWrite(SORTIE_RELAIS, statutDecompte);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user