debug=true gpio=createobject("roGpioControlPort") p = createobject("roMessagePort") audioplayer = createobject("roAudioPlayer") audioplayer.SetPort(p) gpio.SetPort(p) REM Timer objects sTime = createobject("roSystemTime") blinkTimer = CreateObject("roTimer") REM REM Button Inputs REM gpio.EnableInput(0) gpio.EnableInput(1) REM REM GPIO list REM What leds are tied to which buttons. REM if button zeo is pressed, gpio output 4 will used for the led DIM blist[2] blist[0]=4 blist[1]=5 REM REM LED outputs gpio.EnableOutput(4) gpio.EnableOutput(5) REM REM Audio list REM DIM audio_list[2] audio_list[0] = "audio1.mp3" audio_list[1] = "audio2.mp3" audio_on = false gpio_on=false 'checked to determine current gpio status button=99 listen: msg = wait(0,p) if debug print type(msg) if type(msg) = "roGpioButton" and not audio_on then if msg.GetInt() = 0 then audio_on=true button=0 audioplayer.PlayFile(audio_list[button]) if debug print "Button "; button; " pressed." if debug print "Playing .."; audio_list[button] goto set_timer else if msg.GetInt() = 1 then audio_on=true button=1 audioplayer.PlayFile(audio_list[button]) if debug print "Button "; button; " pressed." if debug print "Playing .."; audio_list[button] goto set_timer endif REM checks if audio file has ended, and resets variables. else if type(msg) = "roAudioEvent" then if msg.GetInt() = 8 then audio_on=false if debug print "Audio finished." gpio.SetOutputState(blist[button], false) button=99 endif else if type(msg) = "roTimerEvent" then if debug print "Timer event" if blinkTimer.GetIdentity() = msg.GetSourceIdentity() then if button >=0 and button < 2 then if gpio_on then if debug print "turning off" gpio.SetOutputState(blist[button], false) gpio_on=false else if debug print "turning on" gpio.SetOutputState(blist[button], true) gpio_on=true endif goto set_timer endif endif endif goto listen set_timer: newTimeout = sTime.GetLocalDateTime() newTimeout.AddMilliseconds(500) blinkTimer.SetDateTime(newTimeout) blinkTimer.SetPort(p) blinkTimer.Start() goto listen