B4R Question Arduino mega analog pins declaration

Mostez

Well-Known Member
Licensed User
Longtime User
Hello,
i used this code to read analog value(lithium battery max 3.7 volts) from arduino mega analog pin 0, but i always get 5 volts, i changed the pin to analog 8 (pin 63) and changed battery connection, it reads OK, I would like to know how to declare analog pins 0 to 7 and how to differentiate them from digital pins 0 ~ 7

Thanks
B4X:
private Sub UpdateBatteryInfo
Dim USBsense, BatteryOut As Pin
Dim RawVolts As UInt
Dim BatVolts As Double
Dim isUSB As Boolean
Dim isConnected As String

USBsense.Initialize(0,USBsense.MODE_INPUT)
BatteryOut.Initialize(1,BatteryOut.MODE_INPUT)' if i change pin to 63,it works ok

isUSB = USBsense.DigitalRead
RawVolts = BatteryOut.AnalogRead
BatVolts = RawVolts * (5.0 / 1023.0)
If isUSB Then
    isConnected = "Pluged"
    Else
    isConnected = "XXX"   
End If
Clear
PutString(0,0,"BAT: ",FontArial8x16,True)
PutString(40,0,NumberFormat(BatVolts,1,2),FontArial8x16,True)
PutString(0,2,"USB:",FontArial8x16,True)
PutString(32,2,isConnected,FontArial8x16,True)
Delay(500)
Clear
End Sub
 
Top