|
本帖最后由 zintiger 于 2012-11-28 22:48 编辑
用A0端检测给Arduino供电的电池电压,犯了个低级错误,Arduino用电池电压作为基准电压进行模数转换。这样它是测不出给自己供电的电压的(高于5v时应该是可以的),因为A0测得的值永远是1023。请高手给个建议。
下面是源代码:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
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 from the sensor
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Voltage of A0");
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(sensorValue);
delay(500);
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|