Compare commits
No commits in common. "ecf8711e54e4d3f93908062651636fb818088fc1" and "dc76d0fad23185da8785d11ca3e80183b979f60c" have entirely different histories.
ecf8711e54
...
dc76d0fad2
53
src/main.cpp
53
src/main.cpp
@ -14,13 +14,16 @@
|
|||||||
#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 4
|
||||||
//#define SCL 5
|
#define SCL 5
|
||||||
|
|
||||||
#define SORTIE_RELAIS 16
|
#define SORTIE_RELAIS 1
|
||||||
#define ENCROT_A 12
|
#define LED_FLASH 4
|
||||||
#define ENCROT_B 13
|
//#define LED_BUILTIN 33
|
||||||
#define ENCROT_BP 14
|
|
||||||
|
#define ENCROT_A 2
|
||||||
|
#define ENCROT_B 0
|
||||||
|
#define ENCROT_BP 3
|
||||||
|
|
||||||
// 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);
|
||||||
@ -28,8 +31,8 @@ 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 = 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
|
||||||
@ -63,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();
|
||||||
|
|
||||||
@ -81,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);
|
||||||
@ -96,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;
|
||||||
@ -124,16 +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;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
encoder.setPosition(count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(SORTIE_RELAIS, statutDecompte);
|
digitalWrite(SORTIE_RELAIS, decompteStatut);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user