Menu and battery level

The menu is now done and I may put a video of it in action when I finish the platform sensor setup. One of the things that I have wanted for the monitor was to have a status page that shows information on itself and one of the things was battery level. Measuring a voltage higher that 5V was easy with a voltage divider across the battery (I used two 10kOhm resistors). The coding was long and full of holes at one point but it is working now.


I tried uploading the code on here but it’s not working. I will try something else later.

Update! I have uploaded the code as a .doc file: HERE

Update! It turned out that the < and > brackets in the code was messing with the html and was replaced with & l t ; and & g t ; (spaces added so the post generator doesn’t automatically convert it.

if (buttonstate > 1010 && buttonstate < 1040){
if (menu == 0){
if (selstate == 1){
selstate = 3;
}
else{
selstate = selstate-1;
}
}
}
// center button
else if (buttonstate > 640 && buttonstate < 670){
if (menu == 0){
if (selstate == 3){
selstate = 1;
}
else{
selstate = selstate+1;
}
}
}
// bottom button
else if (buttonstate > 310 && buttonstate < 340){
if (menu == 0){
menu = selstate;
}
else {
menu = 0;
}
}
lcd.clear();
lcd.setCursor(19, 0);
lcd.write(1);
lcd.setCursor(19, 1);
lcd.write(2);
if (menu == 0) {
// set up main menu
lcd.setCursor(4, 0);
lcd.print(“-Main Menu-“);
lcd.setCursor(19, 3);
lcd.write(3);
lcd.setCursor(1, 1);
lcd.print(“Accelerometer”);
lcd.setCursor(1, 2);
lcd.print(“Platform Sensors”);
lcd.setCursor(1, 3);
lcd.print(“Monitor Status”);
lcd.setCursor(0, selstate);
lcd.write(0);

}
else if (menu == 1) {
// set up main menu
lcd.setCursor(1, 0);
lcd.print(“Accelerometer”);
lcd.setCursor(19, 3);
lcd.write(4);
lcd.setCursor(1, 1);
lcd.print(“X = “);
lcd.print(xval);
lcd.setCursor(1, 2);
lcd.print(“Y = “);
lcd.print(yval);
lcd.setCursor(1 , 3);
lcd.print(“Z = “);
lcd.print(zval);
}
else if (menu == 2) {
// set up main menu
lcd.setCursor(1, 0);
lcd.print(“Platform Sensors”);
lcd.setCursor(19, 3);
lcd.write(4);
lcd.setCursor(1, 2);
lcd.print(“Ultra = N/A”);
lcd.setCursor(1, 3);
lcd.print(“Bump = N/A”);
}
else if (menu == 3) {
// set up main menu
lcd.setCursor(1, 0);
lcd.print(“Monitor Status”);
lcd.setCursor(19, 3);
lcd.write(4);
lcd.setCursor(1, 2);
lcd.print(“Battery =”);
float batval = analogRead(batteryPin) * 10.0 / 1000.0; // 1023 is standard but for my resistors 1000 gave more accurate values
lcd.setCursor(11, 2);
lcd.print(batval,1);
lcd.print(“V”);
lcd.setCursor(1, 3);
lcd.print(“Runtime =”);
lcd.setCursor(11, 3);
lcd.print(millis()/1000);
lcd.print(“s”);
}
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s