检测当前 VCC 脚电压的代码

阿喵是朵云 13m2021-08-061193 次点击
```

long readVcc() {‌
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}

void setup() {‌
Serial.begin(9600);
}

void loop() {‌
Serial.println( readVcc(), DEC );
delay(1000);
}
```

Copy, paste into Arduino and see what it returns. This works on an Arduino 168 or 328.
收藏 ♥ 感谢
暂无回复

登录注册 后可回复。




› 相关内容关注微信公众号