1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-14 11:29:26 +01:00

Added comments to Basics examples

This commit is contained in:
Tom Igoe 2012-04-16 07:58:55 -04:00
parent 9a340926da
commit 53fd81fc00
4 changed files with 37 additions and 13 deletions

View File

@ -1,15 +1,21 @@
/* /*
AnalogReadSerial 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. This example code is in the public domain.
*/ */
// the setup routine runs once when you press reset:
void setup() { void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600); Serial.begin(9600);
} }
// the loop routine runs over and over again forever:
void loop() { void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0); int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue); Serial.println(sensorValue);
} }

View File

@ -4,16 +4,21 @@
This example code is in the public domain. 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() { void setup() {
// initialize the digital pin as an output. // initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards: pinMode(led, OUTPUT);
pinMode(13, OUTPUT);
} }
// the loop routine runs over and over again forever:
void loop() { void loop() {
digitalWrite(13, HIGH); // set the LED on digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second delay(1000); // wait for a second
} }

View File

@ -5,14 +5,23 @@
This example code is in the public domain. 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() { void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600); 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() { void loop() {
int sensorValue = digitalRead(2); // read the input pin:
Serial.println(sensorValue); int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
} }

View File

@ -5,19 +5,22 @@
using the analogWrite() function. using the analogWrite() function.
This example code is in the public domain. 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 brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() { void setup() {
// declare pin 9 to be an output: // declare pin 9 to be an output:
pinMode(9, OUTPUT); pinMode(led, OUTPUT);
} }
// the loop routine runs over and over again forever:
void loop() { void loop() {
// set the brightness of pin 9: // set the brightness of pin 9:
analogWrite(9, brightness); analogWrite(led, brightness);
// change the brightness for next time through the loop: // change the brightness for next time through the loop:
brightness = brightness + fadeAmount; brightness = brightness + fadeAmount;
@ -29,3 +32,4 @@ void loop() {
// wait for 30 milliseconds to see the dimming effect // wait for 30 milliseconds to see the dimming effect
delay(30); delay(30);
} }