1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <Wire.h>
#include "Adafruit_MCP23017.h"
int buttonCounter1 = 0;// variable pour le comptage du nombre d'appuis sur le bouton poussoir
int buttonCounter= 0;//Variable pour l'état actuel du bouton poussoir
int lastButtonCounter = 0;// Variable pour l'état précédent du bouton poussoir
bool clignotement1 = true;
const unsigned long Intervaldeclignotement = 250;
unsigned long Millisactuel;
unsigned long Millisprecedent;
void setup() {
Serial.begin(9600);
mcp.begin();
mcp.pinMode(1, OUTPUT);//LED
mcp.pinMode(2, INPUT);//BP1
mcp.pullUp(2, HIGH);
mcp.pinMode(3, INPUT);//BP2
mcp.pullUp(3, HIGH);
mcp.pinMode(4, INPUT);//BP3
mcp.pullUp(4, HIGH);
mcp.pinMode(5, INPUT);//BP4
mcp.pullUp(5, HIGH);
}
void loop() {
if (clignotement1) {
Millisactuel = millis();
if (((unsigned long)(Millisactuel - Millisprecedent) >= Intervaldeclignotement) ) {
mcp.digitalWrite(1, !mcp.digitalRead(1));
Millisprecedent = Millisactuel;
}
} else {
mcp.digitalWrite(1, HIGH);
}
buttonCounter1 = (mcp.digitalRead(2) | mcp.digitalRead(3) | mcp.digitalRead(4) | mcp.digitalRead(5));
if (buttonCounter1 != lastButtonCounter) {
if (buttonCounter1 == LOW) {
buttonCounter++;
}
lastButtonCounter = buttonCounter1;
}
if (buttonCounter >= 3) {
clignotement1 = false;
}
} |
Partager