Events – BrightSign BrightScript 2 Reference Guide User Manual
Page 20
20
Events
Events in BrightScript center around an event loop and the “roMessagePort” Roku object.
Any RokuObject can be posted to a message port. Typically these will be Objects that
are designed to post events. For example, the “roTimer” class posts events of type
“roTimerEvent”.
Example:
print "BrightSign Button-LED Test Running"
p = CreateObject("roMessagePort")
gpio = CreateObject("roGpioControlPort")
gpio.SetPort(p)
while true
msg=wait(0, p)
if type(msg)="roGpioButton" then
butn = msg.GetInt()
if butn <=5 then
gpio.SetOutputState(butn+17,1)
print "Button Pressed: ";butn
sleep(500)
gpio.SetOutputState(butn+17,0)
end if
end if
REM ignore buttons pressed while flashing led above
while p.GetMessage()<>invalid
end while
end while
Note that the following two lines:
while true
msg=wait(0, p)
Could be replaced with:
For each msg in p
And then the last “end while” would become a “next”.