Freenove / Freenove_Ultimate_Starter_Kit_for_ESP32

Apply to FNK0047
Other
138 stars 45 forks source link

Sketch_02.1_ButtonAndLed.ino issue #10

Closed stevekirkby closed 2 months ago

stevekirkby commented 2 months ago

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.

/**********************************************************************
  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);
  }
Zhentao-Lin commented 2 months ago

Thank you for your advice.