Analog Input Problem

Timmay

Member
Licensed User
Longtime User
Hi. I'm new to Basic and Android programming. I'm trying to get analog input (AI) data from a ioio over Bluetooth. I'm using pinoy_ako's Bluetooth app from this:

http://www.b4x.com/forum/attachment...27387319-ioio-board-library-ioiobt-tester.zip

I've added in code which is polling the AI value every second.
I think there's something wrong with my analog input syntax.
Here is my code (what has been changed from above code is in bold):
'Activity module
Sub Process_Globals
Dim YOYO As IOIOBT
Dim led As DigitalOutput
Dim Ana As AnalogInput
Dim timer1 As Timer
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim btnLED As ToggleButton
Dim Label1 As Label
Dim freq As Int 'sampling rate, 1000=1sec

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
activity.AddMenuItem("Connect","Connect")
activity.AddMenuItem("Disconnect","Disconnect")
freq = 1000
timer1.Initialize("Timer1", freq)
timer1.Enabled = True

End Sub

Sub Connect_Click
YOYO.Initialize(True)
YOYO.WaitForConnect()
led = YOYO.OpenDigitalOutput(0,led.OP_NORMAL ,True) ' Enable LED_PIN for output
led.Write(True)
Ana = YOYO.OpenAnalogInput(34)
ToastMessageShow("Library Version: " & YOYo.GetIOIOVersion(YOYO.VER_IOIOLIB),True)
ToastMessageShow("Bootloader Version: " & YOYo.GetIOIOVersion(YOYO.VER_BOOTLOADER),True)
ToastMessageShow("Firmware Version: " & YOYo.GetIOIOVersion(YOYO.VER_FIRMWARE),True)
ToastMessageShow("Hardware Version: " & YOYo.GetIOIOVersion(YOYO.VER_HARDWARE),True)
ToastMessageShow("IOIObt Connected",False)
End Sub

Sub timer1_Tick
time1 = DateTime.Time(DateTime.Now)
date1 = DateTime.Date(DateTime.Now)

Label1.Text = Ana.Voltage
End Sub

Sub Disconnect_Click
YOYO.Disconnect
yoyo.WaitForDisconnect()
ToastMessageShow("It's now safe to disconnect ioio", False)
End Sub


Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub btnLED_CheckedChange(Checked As Boolean)
led.Write(Not(btnLED.Checked)) ' Turn on/off stat LED, active LOW
End Sub
 
Top