Trois boutons

20170923_194305_37012063670_o.jpg

Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
20K-ohm resistor is pulled to 5V. This configuration causes the input to
read HIGH when the switch is open, and LOW when it is closed.

Sketch :

 int sensorValOne, sensorValTwo, sensorValTree ;  
 int prevUpStateOne, prevUpStateTwo, prevUpStateTree;  
 void setup() {  
  //start serial connection  
  Serial.begin(9600);  
  //configure pin2 as an input and enable the internal pull-up resistor  
  pinMode(2, INPUT_PULLUP);  
  pinMode(3, INPUT_PULLUP);  
  pinMode(4, INPUT_PULLUP);  
  pinMode(13, OUTPUT);  
 }  
 void loop() {  
  sensorValOne = digitalRead(2);  
  sensorValTwo = digitalRead(3);  
  sensorValTree = digitalRead(4);  
  if (prevUpStateOne != sensorValOne)  
  { prevUpStateOne = sensorValOne;  
   if (sensorValOne == HIGH) {  
    digitalWrite(13, LOW);  
   } else {  
    Serial.println("Boutton 1 pressed");  
    digitalWrite(13, HIGH);  
   }  
  }  
  if (prevUpStateTwo != sensorValTwo)  
  { prevUpStateTwo = sensorValTwo;  
   if (sensorValTwo == HIGH) {  
    digitalWrite(13, LOW);  
   } else {  
    Serial.println("Boutton 2 pressed");  
    digitalWrite(13, HIGH);  
   }  
  }  
  if (prevUpStateTree != sensorValTree)  
  { prevUpStateTree = sensorValTree;  
   if (sensorValTree == HIGH) {  
    digitalWrite(13, LOW);  
   } else {  
    Serial.println("Boutton 3 pressed");  
    digitalWrite(13, HIGH);  
   }  
  }  
  delay(50);  
 }  

 

Publicités
Articles récents
Commentaires récents
fatima dans Bienvenue !
AdminDroid dans Bienvenue !
fatima dans Bienvenue !
Archives
Catégories
%d blogueurs aiment cette page :