mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
Conflicts: build/shared/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino
This commit is contained in:
commit
c44329d732
@ -1,16 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
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);
|
||||||
delay(1); // delay in between reads for stability
|
delay(1); // delay in between reads for stability
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,20 @@
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
@ -5,15 +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);
|
||||||
delay(1); // short delay in between reads for stability
|
// print out the state of the button:
|
||||||
|
Serial.println(buttonState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
ReadAnalogVoltage
|
||||||
|
Reads an analog input on pin 0, converts it to voltage, and 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);
|
||||||
|
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
|
||||||
|
float voltage = sensorValue * (5.0 / 1023.0);
|
||||||
|
// print out the value you read:
|
||||||
|
Serial.println(voltage);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user