Last active
August 29, 2015 14:16
-
-
Save krobro/441c46493a5eec13a0c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BatteryStatusSerial_Delay | |
// | |
// A simple test script that prints the battery pack voltage to the | |
// serial monitor on your computer with output delay. | |
// | |
// NOTES: | |
// 1 - this is the table of | |
// | |
// Battery Voltage | sensorValue | |
// 4.7 | 773 | |
// 3.2 | 578 | |
// 1.6 | 320 | |
// 0 | 0 | |
// run once, when the sketch starts | |
void setup() | |
{ | |
// setup Serial library at 9600 bps | |
Serial.begin(9600); | |
} | |
// run over and over again | |
void loop() { | |
// read battery sensor value and map it to 0-5 volts | |
int sensorValue = analogRead(BATTERY); | |
int mappedSensorValue = map(sensorValue, 0, 800, 0, 5); | |
// Print battery value out | |
Serial.print("Battery reads: "); | |
Serial.print(mappedSensorValue); | |
Serial.print(" Volts ("); | |
Serial.print(sensorValue); | |
Serial.println(")"); | |
// pause for 1000 ms or 1 second | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment