The adapters in scratchClient can perform complex operations. Especially for buttons, there is an adapter with an 'edge-detector', which sends broadcasts.
In order to use this adater, exchange the config file in scratchClient.
Task: in scratch, load program piandmore_scratchClient_button_event.sb ; start scratchClient with new config file.
Sample code piandmore_scratchClient_button_event.sb
In case scratchClient-software is running, stop with ctrl-c.
Start scratchClient in a terminal (and leave terminal open).
cd ~/scratchClient sudo python src/scratchClient.py -c config/config_piandmore_event.xml
In scratch, enable 'remote sensor connections'
Scratch now receives broadcast events 'button_23_pressed', 'button_23_released'.
The names of the events are defined in config file.
When scratch has received the broadcasts once, th enames are available in :
'when I receive ...'
When no hardware connected, then the event names need to be edited. Or use copy/paste to get it from the configuration.
The difference between the config files is the different input adapter used. The value based input adapter
adapter.gpio.GpioInput
is replaced by an event based adapter
adapter.gpio.GpioEventInput
.
GpioInput documentation is GpioInput
GpioEventInput documentation is GpioEventInput