// 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); } 代码功能 读取电位...
2、读取模拟电压 - Read Analog Voltage Reads an analog input and prints the voltage to the Serial Monitor. 读取模拟输入并打印电压值到串口监视器。 This example shows you how to read an analog input on analog pin 0, convert the values from analogRead() into voltage, and print it out to the...
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); } 火...
ReadAnalogVoltage : 读取一个模拟输入,然后打印其电压值到串口监视器
Serial.println(voltage) 现在,当你打开你在Arduino IDE软件上的串口监视器(可以通过键盘快捷键Ctrl+Shift+M打开),你应该看到一个范围从0.0-5.0的稳定的数据流。随着你转动那个旋钮,这个输入到A0引脚的电压值会随之变化。 /* ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage, and pr...
/*ReadAnalogVoltage 读取模拟电压 Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor. OPEN THE SERIAL MONITOR TO VIEW THE OUTPUT >> Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. ...
(9600);// 初始化串口通信}voidloop(){sensorValue=analogRead(analogInPin);// 读取模拟输入的值voltage=sensorValue*(5.0/1023.0);// 将模拟输入的值转换为电压值// 打印输出Serial.print("sensor = ");Serial.print(sensorValue);Serial.print("\tvol = ");Serial.print(voltage);Serial.println("V");...
BareMinimum - 需要开始一个新的程序的最简框架 Blink - 使LED灯开和关 DigitalReadSerial - 读取一个开关,打印其状态到Arduino串口监视器 Fade - 示范怎么用模拟输出来使LED灯的亮度变淡 ReadAnalogVoltage - 读取一个模拟输入,并打印电压值到串口监视器...
int voltage_value0 =analogRead(A0); int voltage_value1 = analogRead(A1); 声明一个临时浮点变量用于保持浮temp_val等电压值。将该值乘以 0.00488 得到实际电压差,然后除以电阻值以求出电流。0.00488v是Arduino的ADC可以检测到的最小电压。 intsubraction_value =(voltage_value0 - voltage_value1) ; ...
load_voltage = load_voltage + analogRead(voltage_sense); } 负载电压 = 负载电压 / 平均值; load_voltage = ((load_voltage * MAX_VOLT)/1024.0)*6; 返回负载电压; } 这是实际的循环。在这里,测量开关步骤并将数据发送到 DAC。传输数据后,正在测量实际电流和负载电压。这两个值也最终打印在 LCD 上。