Advertisement
computermuseo

sensore sferico/tilt arduino

Apr 18th, 2015
2,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1.  
  2. const int buttonPin = 2; // the number of the pushbutton pin
  3. const int ledPin = 13; // the number of the LED pin
  4. int buttonState = 0; // variable for reading the pushbutton status
  5.  
  6. void setup() {
  7. // initialize the LED pin as an output:
  8. pinMode(ledPin, OUTPUT);
  9. // initialize the pushbutton pin as an input:
  10. pinMode(buttonPin, INPUT);
  11. }
  12.  
  13. void loop(){
  14. // read the state of the pushbutton value:
  15. buttonState = digitalRead(buttonPin);
  16.  
  17. // check if the pushbutton is pressed.
  18. // if it is, the buttonState is HIGH:
  19. if (buttonState == HIGH) {
  20. // turn LED on:
  21. digitalWrite(ledPin, HIGH);
  22. }
  23. else {
  24. // turn LED off:
  25. digitalWrite(ledPin, LOW);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement