File tree Expand file tree Collapse file tree 4 files changed +37
-13
lines changed
build/shared/examples/1.Basics Expand file tree Collapse file tree 4 files changed +37
-13
lines changed Original file line number Diff line number Diff line change 11/*
22 AnalogReadSerial
3- Reads an analog input on pin 0, prints the result to the serial monitor
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.
45
56 This example code is in the public domain.
67 */
78
9+ // the setup routine runs once when you press reset:
810void setup () {
11+ // initialize serial communication at 9600 bits per second:
912 Serial.begin (9600 );
1013}
1114
15+ // the loop routine runs over and over again forever:
1216void loop () {
17+ // read the input on analog pin 0:
1318 int sensorValue = analogRead (A0);
19+ // print out the value you read:
1420 Serial.println (sensorValue);
1521}
Original file line number Diff line number Diff line change 44
55 This example code is in the public domain.
66 */
7+
8+ // Pin 13 has an LED connected on most Arduino boards.
9+ // give it a name:
10+ int led = 13 ;
711
12+ // the setup routine runs once when you press reset:
813void setup () {
914 // initialize the digital pin as an output.
10- // Pin 13 has an LED connected on most Arduino boards:
11- pinMode (13 , OUTPUT);
15+ pinMode (led, OUTPUT);
1216}
1317
18+ // the loop routine runs over and over again forever:
1419void loop () {
15- digitalWrite (13 , HIGH); // set the LED on
16- delay (1000 ); // wait for a second
17- digitalWrite (13 , LOW); // set the LED off
18- delay (1000 ); // wait for a second
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
1924}
Original file line number Diff line number Diff line change 55 This example code is in the public domain.
66 */
77
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:
812void setup () {
13+ // initialize serial communication at 9600 bits per second:
914 Serial.begin (9600 );
10- pinMode (2 , INPUT);
15+ // make the pushbutton's pin an input:
16+ pinMode (pushButton, INPUT);
1117}
1218
19+ // the loop routine runs over and over again forever:
1320void loop () {
14- int sensorValue = digitalRead (2 );
15- Serial.println (sensorValue);
21+ // read the input pin:
22+ int buttonState = digitalRead (pushButton);
23+ // print out the state of the button:
24+ Serial.println (buttonState);
1625}
1726
1827
Original file line number Diff line number Diff line change 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
1011int brightness = 0 ; // how bright the LED is
1112int fadeAmount = 5 ; // how many points to fade the LED by
1213
14+ // the setup routine runs once when you press reset:
1315void 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:
1821void 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+
You can’t perform that action at this time.
0 commit comments