Arduino For Dummies by John Nussey

Arduino For Dummies by John Nussey

Author:John Nussey
Language: eng
Format: epub, azw3, pdf
Publisher: Wiley
Published: 2013-04-24T16:00:00+00:00


// Pin 13 has an LED connected on most Arduino boards.

// give it a name:

int led = 13;

// the setup routine runs once when you press reset:

void setup() {

// initialize the digital pin as an output.

pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever:

void loop() {

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}

The loops can be summarized this way:

1. Turn the LED on.

2. Wait for a second.

3. Turn the LED off.

4. Wait for a second.

This delay or “waiting” is what can be problematic for a lot of people when they try to integrate the blink sketch with another bit of code. When the sketch uses the delay function, it waits for the amount of time specified (in this case, a second), during which it doesn’t do anything else. Effectively, the sketch is twiddling its thumbs.

If you wanted to change something — for example, you wanted the LED to blink only when a light sensor was dark — you might think of writing the code in the loop section something like this:

void loop() {



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.