arduino:arduino_crash_course:program_structure
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
arduino:arduino_crash_course:program_structure [2012/11/03 01:46] – mithat | arduino:arduino_crash_course:program_structure [2017/12/06 01:01] (current) – mithat | ||
---|---|---|---|
Line 3: | Line 3: | ||
===== Main loop ===== | ===== Main loop ===== | ||
- | All Arduino programs | + | Arduino programs |
+ | |||
+ | Arduino sketches all have the same basic structure, consisting | ||
<file c program_structure.ino> | <file c program_structure.ino> | ||
Line 11: | Line 13: | ||
void loop() { | void loop() { | ||
- | // Stuff in here gets run over and over and over again (until you turn the power off). | + | // Stuff in here gets run over and over and over again |
+ | // (until you turn the power off). | ||
} | } | ||
</ | </ | ||
+ | Whatever you write in the body of the '' | ||
===== Blink an LED ===== | ===== Blink an LED ===== | ||
- | Blinking an LED is the microcontroller equivalent to a " | + | Blinking an LED is the microcontroller equivalent to a " |
<file c BlinkMe.ino> | <file c BlinkMe.ino> | ||
Line 26: | Line 30: | ||
void setup() { | void setup() { | ||
- | | + | pinMode(13, OUTPUT); |
- | | + | |
} | } | ||
Line 50: | Line 53: | ||
void setup() { | void setup() { | ||
- | | + | pinMode(ledPin, |
- | | + | |
} | } | ||
Line 62: | Line 64: | ||
</ | </ | ||
- | Now if we need to change the pin number, we only need to change it in one place. | + | One of the advantages of using a named value for the pin number is that if we want to change the pin number we only need to change it in one place. |
Here we use variables also to define delay times: | Here we use variables also to define delay times: | ||
Line 74: | Line 76: | ||
// use variable ledPin to store the pin number that drives the LED | // use variable ledPin to store the pin number that drives the LED | ||
int ledPin = 13; | int ledPin = 13; | ||
+ | |||
// define the LED's on and off times in milliseconds | // define the LED's on and off times in milliseconds | ||
int onTime = 1000; | int onTime = 1000; | ||
Line 79: | Line 82: | ||
void setup() { | void setup() { | ||
- | | + | pinMode(ledPin, |
- | | + | |
} | } | ||
arduino/arduino_crash_course/program_structure.1351907165.txt.gz · Last modified: 2012/11/03 01:46 (external edit)