Thursday, September 14, 2023

Lesson 5: The Blink Sketch- Light an LED

 






The resistor limits the amount of current


   Example Sketch: Blink

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

In setup, we define the built-in LED(Pin 13) as an Output. You could assign another pin (2-12) as an output as well.


The check mark verifies that the code is grammatically correct, such as all statements end with semicolons, all functions are enc,osed in curly brackets {.   }. the right arrow uploads it to the board. Make sure you select the correct board and port.


Try changing the delay times in the code! Then change pin numbers!

No comments:

Post a Comment