ajout encodeur rotatif,
1 pb d'E/S sur mon ESP pour le BP, autre devboard à tester
This commit is contained in:
parent
aaa3086c56
commit
4ee4921f86
@ -15,3 +15,4 @@ framework = arduino
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/Adafruit SSD1306@^2.5.7
|
adafruit/Adafruit SSD1306@^2.5.7
|
||||||
adafruit/Adafruit GFX Library@^1.11.7
|
adafruit/Adafruit GFX Library@^1.11.7
|
||||||
|
mathertel/RotaryEncoder@^1.5.3
|
||||||
|
96
src/main.cpp
96
src/main.cpp
@ -3,15 +3,13 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <RotaryEncoder.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
|
||||||
|
|
||||||
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
|
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
|
||||||
// The pins for I2C are defined by the Wire-library.
|
// The pins for I2C are defined by the Wire-library.
|
||||||
// On an arduino UNO: A4(SDA), A5(SCL)
|
|
||||||
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
|
|
||||||
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
|
|
||||||
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
#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);
|
||||||
@ -19,13 +17,23 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
|||||||
#define SDA 12
|
#define SDA 12
|
||||||
#define SCL 13
|
#define SCL 13
|
||||||
|
|
||||||
#define SORTIE_RELAIS 2
|
#define SORTIE_RELAIS 16
|
||||||
#define LED_FLASH 4
|
#define LED_FLASH 4
|
||||||
#define LED_BUILTIN 33
|
#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
|
// durée par défaut en secondes
|
||||||
int count = 12;
|
int count = 12;
|
||||||
|
bool decompteStatut = false;
|
||||||
|
unsigned long LastUpdate = 0;
|
||||||
|
unsigned long LastReadBP = 0;
|
||||||
|
|
||||||
#define LOGO_HEIGHT 32
|
#define LOGO_HEIGHT 32
|
||||||
#define LOGO_WIDTH 32
|
#define LOGO_WIDTH 32
|
||||||
@ -42,25 +50,10 @@ const unsigned char bitmap_K [] PROGMEM = {
|
|||||||
0x00, 0xff, 0xf0, 0x07, 0x00, 0xff, 0xf8, 0x03, 0x00, 0xff, 0xf8, 0x01, 0x00, 0xff, 0xfc, 0x01
|
0x00, 0xff, 0xf0, 0x07, 0x00, 0xff, 0xf8, 0x03, 0x00, 0xff, 0xf8, 0x01, 0x00, 0xff, 0xfc, 0x01
|
||||||
};
|
};
|
||||||
|
|
||||||
void testdrawchar(void) {
|
|
||||||
display.clearDisplay();
|
|
||||||
|
|
||||||
display.setTextSize(5); // Normal 1:1 pixel scale
|
|
||||||
display.setTextColor(SSD1306_WHITE); // Draw white text
|
|
||||||
display.setCursor(0, 0); // Start at top-left corner
|
|
||||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
|
||||||
|
|
||||||
// Not all the characters will fit on the display. This is normal.
|
|
||||||
// Library will draw what it can and the rest will be clipped.
|
|
||||||
for(int16_t i=0; i<256; i++) {
|
|
||||||
if(i == '\n') display.write(' ');
|
|
||||||
else display.write(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
display.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
pinMode(ENCROT_A, INPUT);
|
||||||
|
pinMode(ENCROT_B, INPUT);
|
||||||
|
pinMode(ENCROT_BP, INPUT);
|
||||||
pinMode(SORTIE_RELAIS, OUTPUT);
|
pinMode(SORTIE_RELAIS, OUTPUT);
|
||||||
digitalWrite(SORTIE_RELAIS, LOW);
|
digitalWrite(SORTIE_RELAIS, LOW);
|
||||||
|
|
||||||
@ -83,30 +76,53 @@ void setup() {
|
|||||||
bitmap_K, LOGO_WIDTH, LOGO_HEIGHT, 1);
|
bitmap_K, LOGO_WIDTH, LOGO_HEIGHT, 1);
|
||||||
display.display();
|
display.display();
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
||||||
// Clear the buffer
|
|
||||||
display.clearDisplay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
digitalWrite(SORTIE_RELAIS, HIGH);
|
//digitalWrite(SORTIE_RELAIS, HIGH);
|
||||||
|
display.setTextSize(6);
|
||||||
for (int i = count; i > 0; i--)
|
|
||||||
{
|
|
||||||
display.clearDisplay();
|
|
||||||
|
|
||||||
display.setTextSize(6); // Normal 1:1 pixel scale
|
|
||||||
display.setTextColor(SSD1306_WHITE); // Draw white text
|
display.setTextColor(SSD1306_WHITE); // Draw white text
|
||||||
display.setCursor(0, 20); // Start at top-left corner
|
unsigned long currentMillis = millis();
|
||||||
|
|
||||||
display.println(i);
|
if (decompteStatut) {
|
||||||
|
if (count > 0) {
|
||||||
|
if (currentMillis - LastUpdate >= 1000) {
|
||||||
|
--count;
|
||||||
|
LastUpdate = currentMillis;
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println(count);
|
||||||
display.display();
|
display.display();
|
||||||
display.startscrollright(0x00, 0x0F);
|
}
|
||||||
delay(1000);
|
}
|
||||||
|
else {
|
||||||
|
decompteStatut = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
static int pos = 0;
|
||||||
|
encoder.tick();
|
||||||
|
|
||||||
|
int newPos = encoder.getPosition();
|
||||||
|
if (pos != newPos) {
|
||||||
|
if (newPos < 0) {
|
||||||
|
newPos = 0;
|
||||||
|
encoder.setPosition(0);
|
||||||
|
}
|
||||||
|
pos = newPos;
|
||||||
|
count = newPos;
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println(count);
|
||||||
|
display.display();
|
||||||
|
} // if
|
||||||
}
|
}
|
||||||
|
|
||||||
display.clearDisplay();
|
if (!digitalRead(ENCROT_BP) && (LastReadBP - currentMillis > 250)){
|
||||||
display.display();
|
LastReadBP = currentMillis;
|
||||||
digitalWrite(SORTIE_RELAIS, LOW);
|
decompteStatut = !decompteStatut;
|
||||||
delay(3000);
|
}
|
||||||
|
|
||||||
|
digitalWrite(SORTIE_RELAIS, decompteStatut);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user