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?
: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)
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.
After thinking about this a little, this might work:
Hope this works for you. If you have a momentary button you may have to keep the button pushed until the script starts.
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.
Outstanding! I'm glad I was able to help. Have fun!!