2. Digital Write
Blink a LED with digital write
Components Required
Introduction
Learning Outcomes
- Pin Mode
- Digital Write
- Delay Functions
Theory
Methodology
Magicbit equipped with four onboard LED in Magicbit development board, Lets select yellow LED (which is wired to D16)
By setting the output state to high of the LED pin will turn on the LED and by setting the output state to LOW will turn off the LED.
Code
void setup(){
pinMode(16,OUTPUT);
}
void loop(){
digitalWrite(16,HIGH);
delay(1000);
digitalWrite(16,LOW);
delay(1000);
}
Explanation
pinMode(pin, Mode): Configures the specified pin to behave either as an input or an output. Here, we use the pin as an output
digitalWrite(pin No, State): Write a HIGH or a LOW value to a digital pin. Pin mode must be set up for the same pin in Setup to work this function properly.
delay(ms): Pauses the program for the amount of time (in milliseconds) specified as a parameter. (note, 1000 milliseconds equals one second)
Note: Write code for a Knight Rider pattern using onboard LEDs of Magicbit