Read battery level & 5 buttons using analogue input A0

Place code snippets and demo code here
Post Reply
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Read battery level & 5 buttons using analogue input A0

Post by Electroguard »

Another neat example from Liu Palm showing how to use ADC input to read battery voltage plus 5 navigation buttons using a resistor divider...

(from Liu Palm)

adckey.jpg

Code: [Local Link Removed for Guests]

'==========================
' Timer Interrupt @10Hz
'==========================
timer10Hz:
  adckey = ADC
  IF adckey<220 THEN
    adcbat = ADC
  ENDIF
  adckey = adckey*1.75
  adckey = adckey\adcbat
  IF adckeylast <> adckey THEN
    adckeylast = adckey
    key = adckey
  ENDIF  
RETURN  

' The key value for UP, DOWN, LEFT, RIGHT and PUSH will be "5", "6", "7", "8" & "9", key release will be "1"
' The " (adcbat\0.473)/100 "  will be battery voltage (in V)
You do not have the required permissions to view the files attached to this post.
Post Reply