Last active
October 4, 2018 17:57
Identifie le bouton pressé sur un module LED & KEY branché à un ESP8266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************** | |
Identifie le bouton pressé sur un module | |
LED & KEY branché à un ESP8266 | |
https://electroniqueamateur.blogspot.com/2018/09/esp8266-et-afficheur-base-de-tm1638.html | |
Utilisation de la bibliothèque ErriezTM1638 | |
Source: https://github.com/Erriez/ErriezTM1638 | |
Documentation: https://erriez.github.io/ErriezTM1638 | |
**************************************************/ | |
#include <ErriezTM1638.h> | |
// Définition des broches liées au module LED & KEY | |
#define TM1638_CLK_PIN 16 | |
#define TM1638_DIO_PIN 5 | |
#define TM1638_STB0_PIN 4 | |
// création d'un objet tm1638 | |
TM1638 tm1638(TM1638_CLK_PIN, TM1638_DIO_PIN, TM1638_STB0_PIN); | |
void setup() | |
{ | |
Serial.begin(115200); | |
tm1638.begin(); | |
tm1638.displayOff(); | |
tm1638.clear(); | |
tm1638.setBrightness(3); | |
tm1638.displayOn(); | |
} | |
void loop() | |
{ | |
static uint32_t boutonsPrecedents = 0; | |
uint32_t boutons; | |
// Read 32-bit keys | |
boutons = tm1638.getKeys(); | |
// Détection du bouton pressé | |
if (boutonsPrecedents != boutons) { | |
boutonsPrecedents = boutons; | |
if (boutons == 1) { | |
Serial.println("Bouton S1 enfonce"); | |
} | |
if (boutons == 256) { | |
Serial.println("Bouton S2 enfonce"); | |
} | |
if (boutons == 65536) { | |
Serial.println("Bouton S3 enfonce"); | |
} | |
if (boutons == 16777216) { | |
Serial.println("Bouton S4 enfonce"); | |
} | |
if (boutons == 16) { | |
Serial.println("Bouton S5 enfonce"); | |
} | |
if (boutons == 4096) { | |
Serial.println("Bouton S6 enfonce"); | |
} | |
if (boutons == 1048576) { | |
Serial.println("Bouton S7 enfonce"); | |
} | |
if (boutons == 268435456) { | |
Serial.println("Bouton S8 enfonce"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment