End-Stop Sensor | ||
Avant le Setup | Importation de la bibliothèque | #include |
Création de l'objet et Configuration de la broche | ezButton limitSwitch(7); | |
Dans le Setup | Configuration du temps de rebond | limitSwitch.setDebounceTime(50); |
Dans le Loop | Utilisation | limitSwitch.loop(); if(limitSwitch.isPressed()) Serial.println("L'interrupteur de fin de course: NON TOUCHÉ -> TOUCHÉ"); if(limitSwitch.isReleased()) Serial.println("L'interrupteur de fin de course: TOUCHÉ -> NON TOUCHÉ"); int state = limitSwitch.getState(); if(state == HIGH) Serial.println("L'interrupteur de fin de course: NON TOUCHÉ"); else Serial.println("L'interrupteur de fin de course: TOUCHÉ"); |
1 #include
2
3 ezButton limitSwitch(7); // créer un objet ezButton qui s'attache à la broche 7
4
5 void setup() {
6 Serial.begin(9600);
7 limitSwitch.setDebounceTime(50); // fixer le temps de rebond à 50 millisecondes
8
9 }
10
11 void loop() {
12 limitSwitch.loop(); // DOIT appeler la fonction loop() en premier
13
14 if(limitSwitch.isPressed())
15 Serial.println("L'interrupteur de fin de course: NON TOUCHÉ -> TOUCHÉ");
16
17 if(limitSwitch.isReleased())
18 Serial.println("L'interrupteur de fin de course: TOUCHÉ -> NON TOUCHÉ");
19
20 int state = limitSwitch.getState();
21 if(state == HIGH)
22 Serial.println("L'interrupteur de fin de course: NON TOUCHÉ");
23 else
24 Serial.println("L'interrupteur de fin de course: TOUCHÉ");
25
26 }
Vous avez entré un nom de page invalide, avec un ou plusieurs caractères suivants :
< > @ ~ : * € £ ` + = / \ | [ ] { } ; ? #