Advertisement
makispaiktis

ArduinoBasics - 2. Button and Led

Mar 20th, 2021 (edited)
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int ledPin = 6;
  2. int buttonPin = 11;
  3. bool isPressed;     // Για το αν έχει πατηθεί το κουμπί
  4.  
  5. void setup()
  6. {
  7.   pinMode(buttonPin, INPUT);
  8.   pinMode(ledPin, OUTPUT);
  9. }
  10.  
  11. void loop()
  12. {
  13.   isPressed = digitalRead(buttonPin);
  14.   // Μόλις εκτελεστεί η παραπάνω εντολή, θα έχω στην μεταβλητή
  15.   // μου την κατάσταση του button που έχω στο buttonPin
  16.   digitalWrite(ledPin, isPressed);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement