Todays project will involve connecting 2 LEDs to our Arduino (don't forget the resistors!) and making them flash.
Each LED will be connected to its own digital pin, through a resistor and finally to a ground pin.
Both LEDs can go to the same ground pin but they MUST be connected to their own digital pin. (pins 10 and 16 in the example)
pinMode(pinNumber, mode)
Sets a digital pin to either OUTPUT or INPUT mode. To send a current through the pin and light our LED we need to set the pinNumber of the pin we are using and set the mode to OUTPUT. INPUT is used when we want the pin to receive a signal.
Should usually only be set one time in the setup(){} block.
digitalWrite(pinNumber, mode)
Sets a digital pin to either on or off (5 volts). Set the pin mode to HIGH to turn it on and LOW to turn it off.
delay(milliseconds)
Forces the Arduino to wait for however many milliseconds. The Arduino will not read the next line of code until the time has passed. 1000 milliseconds = 1 second.
Remember led1 is on pin 10
Remember led2 is on pin 16
void setup() {
Set led1 to output mode
Set led2 to output mode
}
void loop() {
Turn led1 on
Turn led2 off
Wait 20% of a second
Turn led1 off
Turn led2 on
Wait 20% of a second
}
int led1 = 10; // Remember led1 is on pin 10
int led2 = 16; // Remember led2 is on pin 16
void setup() {
pinMode(led1, OUTPUT); // Set led1 to output mode
pinMode(led2, OUTPUT); // Set led2 to output mode
}
void loop() {
digitalWrite(led1, HIGH); // Turn led1 on
digitalWrite(led2, LOW); // Turn led2 off
delay(200); // Wait 20% of a second
digitalWrite(led1, LOW); // Turn led1 off
digitalWrite(led2, HIGH); // Turn led2 on
delay(200); // Wait 20% of a second
}
None Today :-)
... Next week though