![]()
Take a look at the comments (the text after the “//” symbols) above each command. See if you can start to spot patterns in the code. A great way to write your own code is to copy and paste sections of your already existing code and modify the copied code to fit your new project. NOTE: An external LED needs a resistor in the circuit to keep it from burning out. The higher the resistance, the dimmer the LED will appear but the longer it will last. NOTE: Make sure the long lead on the LED is connected to positive (pin 13 in this case); LEDs are directional and won’t work if these connections are reversed.
1 220 Ohm Resistor 1 Arduino UNO R3 1 Breadboard Connector Wires
Code:
//------------- Code Starts Here ----------------------------
//-----------------------------------------
//Published by IntroductionToArduino.com
//Created by Paul Illsley (www.paulillsley.com)
//Please use and share so others can enjoy
//-----------------------------------------
void setup() {
// setting pin 13 (the LED) as an output (this is also the pin for the UNO's on-board LED).
pinMode(13,OUTPUT);
}
void loop() {
// setting the voltage of pin 13 to HIGH (5 volts), the LED turns on
digitalWrite(13,HIGH);
// delay 1000 milliseconds (1 second)
delay(1000);
// setting the voltage of pin 13 to LOW (0 volts), the LED turns off
digitalWrite(13,LOW);
// delay 1000 milliseconds (1 second)
delay(1000);
}
//------------- Code Stops Here ----------------------------
Return to www.introductiontoarduino.com
|