Mercurial > ukubik
changeset 65:9bf3dcb10dac
Battery guard with a delay
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 27 Aug 2014 19:40:50 +0200 |
| parents | 0c93a45e1477 |
| children | 623f793006ff |
| files | joy.py servo/servo.ino |
| diffstat | 2 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/joy.py Wed Aug 27 18:57:32 2014 +0200 +++ b/joy.py Wed Aug 27 19:40:50 2014 +0200 @@ -7,7 +7,7 @@ import kubik import creep -FPS = 24 +FPS = 50 class Walk(creep.Creep):
--- a/servo/servo.ino Wed Aug 27 18:57:32 2014 +0200 +++ b/servo/servo.ino Wed Aug 27 19:40:50 2014 +0200 @@ -59,6 +59,7 @@ int serial_command = 0; int accel_buffer[MAX_ACCEL_BUFFER][3]; int accel_buffer_index = 0; +int battery_fail = 0; unsigned long last_tick = 0; @@ -252,11 +253,17 @@ void check_battery() { int reading = analogRead(A7); if (reading < 762) { - /* At about 3.74V start an alarm. */ + /* At about 3.74V start worrying. */ + battery_fail += 1; + } else { + battery_fail = max(0, battery_fail - 1); + } + if (battery_fail > 10) { + /* If it doesn't improve for a second, beep. */ tone(A3, 880, 100); } - if (reading < 758) { - /* At about 3.72V shut down. */ + if (battery_fail > 40) { + /* If it stays bad for 4s, shut down. */ fold(); } }
