From 53fd81fc00fbbc7a30f0b594ab90b670d53c0079 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 16 Apr 2012 07:58:55 -0400 Subject: [PATCH] Added comments to Basics examples --- .../AnalogReadSerial/AnalogReadSerial.ino | 8 +++++++- build/shared/examples/1.Basics/Blink/Blink.ino | 17 +++++++++++------ .../DigitalReadSerial/DigitalReadSerial.ino | 15 ++++++++++++--- build/shared/examples/1.Basics/Fade/Fade.ino | 10 +++++++--- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino b/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino index 2ba6fa73b..7664564d1 100644 --- a/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino +++ b/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino @@ -1,15 +1,21 @@ /* AnalogReadSerial - Reads an analog input on pin 0, prints the result to the serial monitor + Reads an analog input on pin 0, prints the result to the serial monitor. + Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ +// the setup routine runs once when you press reset: void setup() { + // initialize serial communication at 9600 bits per second: Serial.begin(9600); } +// the loop routine runs over and over again forever: void loop() { + // read the input on analog pin 0: int sensorValue = analogRead(A0); + // print out the value you read: Serial.println(sensorValue); } diff --git a/build/shared/examples/1.Basics/Blink/Blink.ino b/build/shared/examples/1.Basics/Blink/Blink.ino index 1953c3908..15b991140 100644 --- a/build/shared/examples/1.Basics/Blink/Blink.ino +++ b/build/shared/examples/1.Basics/Blink/Blink.ino @@ -4,16 +4,21 @@ This example code is in the public domain. */ + +// 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. - // Pin 13 has an LED connected on most Arduino boards: - pinMode(13, OUTPUT); + pinMode(led, OUTPUT); } +// the loop routine runs over and over again forever: void loop() { - digitalWrite(13, HIGH); // set the LED on - delay(1000); // wait for a second - digitalWrite(13, LOW); // set the LED off - delay(1000); // wait for a second + 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 } diff --git a/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino b/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino index 68e4dc966..35b3aae88 100644 --- a/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino +++ b/build/shared/examples/1.Basics/DigitalReadSerial/DigitalReadSerial.ino @@ -5,14 +5,23 @@ This example code is in the public domain. */ +// digital pin 2 has a pushbutton attached to it. Give it a name: +int pushButton = 2; + +// the setup routine runs once when you press reset: void setup() { + // initialize serial communication at 9600 bits per second: Serial.begin(9600); - pinMode(2, INPUT); + // make the pushbutton's pin an input: + pinMode(pushButton, INPUT); } +// the loop routine runs over and over again forever: void loop() { - int sensorValue = digitalRead(2); - Serial.println(sensorValue); + // read the input pin: + int buttonState = digitalRead(pushButton); + // print out the state of the button: + Serial.println(buttonState); } diff --git a/build/shared/examples/1.Basics/Fade/Fade.ino b/build/shared/examples/1.Basics/Fade/Fade.ino index b47bf4307..18f23caba 100644 --- a/build/shared/examples/1.Basics/Fade/Fade.ino +++ b/build/shared/examples/1.Basics/Fade/Fade.ino @@ -5,19 +5,22 @@ using the analogWrite() function. This example code is in the public domain. - */ + +int led = 9; // the pin that the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by +// the setup routine runs once when you press reset: void setup() { // declare pin 9 to be an output: - pinMode(9, OUTPUT); + pinMode(led, OUTPUT); } +// the loop routine runs over and over again forever: void loop() { // set the brightness of pin 9: - analogWrite(9, brightness); + analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; @@ -29,3 +32,4 @@ void loop() { // wait for 30 milliseconds to see the dimming effect delay(30); } +