document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. int ledPin = 8; //PB2 pin is the number 8
  2. int buttonPin = 7; //Why number 7? Because my button is linked to the PA7
  3. int buttonState; //buttonState
  4.  
  5. void setup() {
  6. pinMode(ledPin, OUTPUT); //My led will remain an OUTPUT
  7. pinMode(buttonPin, INPUT); //The button will be the INPUT
  8. digitalWrite(buttonPin, HIGH); //activate button internal R-pull
  9. }
  10.  
  11. void loop() { //start infinite loop
  12. digitalWrite(ledPin, LOW); //This time I want the led switched off at the beginning
  13. buttonState = digitalRead(buttonPin);
  14.  
  15. if(buttonState == LOW){ //I added an IF condition, because if button is pressed my led will switched on
  16. digitalWrite(ledPin, HIGH); //LED is switched on
  17. }
  18.  
  19. else{
  20. digitalWrite(ledPin, LOW); //otherwise the led is switched off
  21. }
  22. }
');