Back to Browse

Flowchart LED Thinker CAD

126 views
Oct 1, 2024
14:06

Please watch my video and follow me. Create your Tinkercad account using your school email. Make sure to follow the flowchart to turn the LED on and off. I hope you enjoy the video. Study well and always exercise at home to become a good programmer. Explain: This C++ code is for an Arduino board, where you're controlling an LED using a button. Here's a line-by-line explanation of the code: int LED = 11; This defines a variable LED and assigns it the value 11. It indicates that the LED is connected to pin 11 of the Arduino board. int BUTTON = 2; This defines a variable BUTTON and assigns it the value 2. It indicates that the button is connected to pin 2 of the Arduino board. void setup() This function runs once when the Arduino is powered on or reset. It's used to initialize settings for the pins. pinMode(LED, OUTPUT); This sets pin 11 (the LED pin) as an output, meaning it can send current to an LED to light it up. pinMode(2, INPUT); This sets pin 2 (the button pin) as an input, meaning it will read the state of the button (pressed or not pressed). void loop() This function runs continuously after setup(). It constantly checks the state of the button and controls the LED accordingly. if (digitalRead(2) == LOW) digitalRead(2) reads the state of pin 2 (the button pin). It checks if the button is pressed (LOW), assuming the button is wired to pull the pin LOW when pressed. digitalWrite(11, HIGH); If the button is pressed, this line turns the LED ON by writing HIGH to pin 11 (LED pin). else { digitalWrite(LED, LOW); } If the button is not pressed, the LED is turned OFF by writing LOW to pin 11. Pseudocode: Here’s the pseudocode for the same program: Define LED_PIN = 11 The pin where the LED is connected. Define BUTTON_PIN = 2 The pin where the button is connected. Initialize: Set the LED_PIN as OUTPUT. Set the BUTTON_PIN as INPUT. Repeat forever (main loop): Check the state of the button: If the button is pressed (state is LOW): Turn the LED ON. Else: Turn the LED OFF.

Download

0 formats

No download links available.

Flowchart LED Thinker CAD | NatokHD