In this example we use a variable resistor (a potentiometer or a photoresistor), we read its value using one analog input of an Arduino board and we change the blink rate of the built-in LED accordingly. The resistor's analog value is read as a voltage because this is how the analog ...
By Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/AnalogInput */ int sensorPin = A0; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int sensorValue = 0; // variable to store the value coming ...
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); } [...
This example code is in the public domain. http://www.arduino.cc/en/Tutorial/AnalogInput */intsensorPin=A0;// select the input pin for the potentiometerintledPin=13;// select the pin for the LEDintsensorValue=0;// variable to store the value coming from the sensorvoidsetup(){// decla...
ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage, and prints the result...
This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage */// the setup routine runs once when you press reset:voidsetup(){// initialize serial communication at 9600 bits per second:Serial.begin(9600);}// the loop routine runs over and over again ...
这时,我们可以在Arduino IDE里编入以下代码: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:float sensorValue = analogRead(A0);// convert...
This example code is in the public domain.*/intsensorValue =0;voidsetup() { pinMode(A0, INPUT); Serial.begin(9600); }voidloop() {//read the input on analog pin 0:sensorValue =analogRead(A0);//print out the value you read:Serial.println(sensorValue); ...
Blink: 使一个LED灯开关. DigitalReadSerial: 读取引脚,打印状态到Arduino串口监视器 AnalogReadSerial: 读取一个电位计,打印它的状态到Arduino串口监视器 Fade: Demonstrates 示范用模拟输出使LED灯亮度变淡 ReadAnalogVoltage : 读取一个模拟输入,然后打印其电压值到串口监视器...
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int analogOutPin = 9; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) ...