Skip to content

Commit 997afb9

Browse files
committed
Merged master
2 parents 3edc5d6 + 5a5bc33 commit 997afb9

File tree

80 files changed

+1242
-907
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1242
-907
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
AnalogReadSerial
3+
Reads an analog input on pin 0, prints the result to the serial monitor.
4+
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
5+
6+
This example code is in the public domain.
7+
*/
8+
9+
// the setup routine runs once when you press reset:
10+
void setup() {
11+
// initialize serial communication at 9600 bits per second:
12+
Serial.begin(9600);
13+
}
14+
15+
// the loop routine runs over and over again forever:
16+
void loop() {
17+
// read the input on analog pin 0:
18+
int sensorValue = analogRead(A0);
19+
// print out the value you read:
20+
Serial.println(sensorValue);
21+
delay(1); // delay in between reads for stability
22+
}

examples/01.Basics/Blink/Blink.ino

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Blink
3+
Turns on an LED on for one second, then off for one second, repeatedly.
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
// Pin 13 has an LED connected on most Arduino boards.
9+
// give it a name:
10+
int led = 13;
11+
12+
// the setup routine runs once when you press reset:
13+
void setup() {
14+
// initialize the digital pin as an output.
15+
pinMode(led, OUTPUT);
16+
}
17+
18+
// the loop routine runs over and over again forever:
19+
void loop() {
20+
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
21+
delay(1000); // wait for a second
22+
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
23+
delay(1000); // wait for a second
24+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
DigitalReadSerial
3+
Reads a digital input on pin 2, prints the result to the serial monitor
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
// digital pin 2 has a pushbutton attached to it. Give it a name:
9+
int pushButton = 2;
10+
11+
// the setup routine runs once when you press reset:
12+
void setup() {
13+
// initialize serial communication at 9600 bits per second:
14+
Serial.begin(9600);
15+
// make the pushbutton's pin an input:
16+
pinMode(pushButton, INPUT);
17+
}
18+
19+
// the loop routine runs over and over again forever:
20+
void loop() {
21+
// read the input pin:
22+
int buttonState = digitalRead(pushButton);
23+
// print out the state of the button:
24+
Serial.println(buttonState);
25+
delay(1); // delay in between reads for stability
26+
}
27+
28+
29+

examples/1.Basics/Fade/Fade.ino renamed to examples/01.Basics/Fade/Fade.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
using the analogWrite() function.
66
77
This example code is in the public domain.
8-
98
*/
9+
10+
int led = 9; // the pin that the LED is attached to
1011
int brightness = 0; // how bright the LED is
1112
int fadeAmount = 5; // how many points to fade the LED by
1213

14+
// the setup routine runs once when you press reset:
1315
void setup() {
1416
// declare pin 9 to be an output:
15-
pinMode(9, OUTPUT);
17+
pinMode(led, OUTPUT);
1618
}
1719

20+
// the loop routine runs over and over again forever:
1821
void loop() {
1922
// set the brightness of pin 9:
20-
analogWrite(9, brightness);
23+
analogWrite(led, brightness);
2124

2225
// change the brightness for next time through the loop:
2326
brightness = brightness + fadeAmount;
@@ -29,3 +32,4 @@ void loop() {
2932
// wait for 30 milliseconds to see the dimming effect
3033
delay(30);
3134
}
35+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
ReadAnalogVoltage
3+
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
4+
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
5+
6+
This example code is in the public domain.
7+
*/
8+
9+
// the setup routine runs once when you press reset:
10+
void setup() {
11+
// initialize serial communication at 9600 bits per second:
12+
Serial.begin(9600);
13+
}
14+
15+
// the loop routine runs over and over again forever:
16+
void loop() {
17+
// read the input on analog pin 0:
18+
int sensorValue = analogRead(A0);
19+
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
20+
float voltage = sensorValue * (5.0 / 1023.0);
21+
// print out the value you read:
22+
Serial.println(voltage);
23+
}
File renamed without changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Input Pullup Serial
3+
4+
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
5+
digital input on pin 2 and prints the results to the serial monitor.
6+
7+
The circuit:
8+
* Momentary switch attached from pin 2 to ground
9+
* Built-in LED on pin 13
10+
11+
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
12+
20K-ohm resistor is pulled to 5V. This configuration causes the input to
13+
read HIGH when the switch is open, and LOW when it is closed.
14+
15+
created 14 March 2012
16+
by Scott Fitzgerald
17+
18+
http://www.arduino.cc/en/Tutorial/InputPullupSerial
19+
20+
This example code is in the public domain
21+
22+
*/
23+
24+
void setup(){
25+
//start serial connection
26+
Serial.begin(9600);
27+
//configure pin2 as an input and enable the internal pull-up resistor
28+
pinMode(2, INPUT_PULLUP);
29+
pinMode(13, OUTPUT);
30+
31+
}
32+
33+
void loop(){
34+
//read the pushbutton value into a variable
35+
int sensorVal = digitalRead(2);
36+
//print out the value of the pushbutton
37+
Serial.println(sensorVal);
38+
39+
// Keep in mind the pullup means the pushbutton's
40+
// logic is inverted. It goes HIGH when it's open,
41+
// and LOW when it's pressed. Turn on pin 13 when the
42+
// button's pressed, and off when it's not:
43+
if (sensorVal == HIGH) {
44+
digitalWrite(13, LOW);
45+
}
46+
else {
47+
digitalWrite(13, HIGH);
48+
}
49+
}
50+
51+
52+

0 commit comments

Comments
 (0)