Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked
Resolved Resolved by Dave Schulpius!

ADC Port Script Help

I'm trying to create a script with a loop for my Wall.E. to monitor two button sensors wired to the ADC0 via resistors on an ioTiny.  I want my script to continuously loop and if either ADC value range is encountered a specific sound file will play.  

The script behavior that I get that I don't want is, which ever button I press, I then I have to press the other button before my script will respond.  I want to be able press button1 as many times as I want and have the sound file play and or press button2 as many times and have the sound file play.  I don't want to have to press buton1 > then button2 > then button1.....or conversely button2 > then button1 > then button2.

I know it's not hardware because I see in the ADC Value control change correctly with the value sitting at 1 when nothing is pressed.  It shows around 230 for the value with a press of button1 and a value of around 211 when pressing button2

What does it look like I'm doing wrong in my script?

Code:

:ReadSensors

#Button1
if(ADC_Wait_Between( 0, 220, 250 ))
controlCommand("Soundboard v4", "Track_6")
endif

#Button2
if(ADC_Wait_Between( 0, 200, 217 ))
controlCommand("Soundboard v4", "Track_18")
endif

Goto(ReadSensors)


Related Hardware EZ-Robot EZ-B IoTiny
Related Controls Script ADC Value
AI Support Bot
Related Content
Synthiam
#1   — Edited
So, I assume that you are using the resistors to keep your voltages of each button at different levels? If sounds sounds like button one is between 220 & 250 when activated and button 2 is between 200 & 217? I can't see how any of the ADC wait commands would work if your button voltage when opened is floating near zero. It will always catch the first waiting script at the lower voltage when the button is closed as the voltage raises. 

I think I remember this being discussed here a few years ago and I think someone came up with a way to do this. I just can't remember.

A simpler solution would be to use two different ADC ports if you have one available.
#2   — Edited
After thinking about this a little, this might work:

Code:


:Start

ADC_Wait(ADC0, HIGHER, 100) #Waits for one of the buttons on ADC0 to be pushed

Sleep(1000) #Script waits until ADC voltage stabilizes after one of your two buttons attached to ADC0 are pushed This can be adjusted if it's not long enough.

$Button_Selection = GetADC(adc0)

IF ($Button_Selection >= 220)
goto(Button1)
ENDIF

IF ($Button_Selection <= 217)
goto(Button2)
ENDIF

:Button1
controlCommand("Soundboard v4", "Track_6")
Goto:(End)

:Button2
controlCommand("Soundboard v4", "Track_18")

:End
sleep(2000)

goto(Start)
Hope this works for you. If you have a momentary button you may have to keep the button pushed until the script starts.
#3  
Thank you so much Dave for taking the time to give me this example!!  It does exactly what I wanted!!  I just had to change the sleep value from 1000 to 100 so it responded quicker. :D