For the LED to switch on when the button is pressed, versions of this file and the PDF should be updated to the following. This has been corrected in your YouTube video.
/**********************************************************************
Filename : ButtonAndLed
Description : Control led by button.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_LED 2
#define PIN_BUTTON 13
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin PIN_LED as an output.
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_BUTTON, INPUT);
}
// the loop function runs over and over again forever
void loop() {
if (digitalRead(PIN_BUTTON) == LOW) {
digitalWrite(PIN_LED,HIGH);
}else{
digitalWrite(PIN_LED,LOW);
}
C/Sketches/Sketch_02.1_ButtonAndLed.ino
For the LED to switch on when the button is pressed, versions of this file and the PDF should be updated to the following. This has been corrected in your YouTube video.