0
|
1 This package enables communication between Python and Scratch using the
|
|
2 remote sensors feature of Scratch.
|
|
3
|
|
4 Remember to enable remote sensors in Scratch! To do this:
|
|
5
|
|
6 1. Go to Sensing
|
|
7 2. Right-click on a 'sensor value'
|
|
8 3. Select 'enable remote sensor connections'
|
|
9
|
|
10 Example usage:
|
|
11
|
|
12 ::
|
|
13
|
|
14 import scratch
|
|
15 s = scratch.Scratch()
|
|
16
|
|
17 # to make a broadcast to scratch
|
|
18 s.broadcast("from python")
|
|
19
|
|
20 # to receive an update from scratch
|
|
21 message = s.receive()
|
|
22 # blocks until an update is received
|
|
23 # message returned as {'broadcast': [], 'sensor-update': {'scratchvar': '64'}}
|
|
24 # or {'broadcast': ['from scratch'], 'sensor-update': {}}
|
|
25 # where scratchvar is the name of a variable in scratch
|
|
26 # and 'from scratch' is the name of a scratch broadcast
|
|
27
|
|
28 # send sensor updates to scratch
|
|
29 data = {}
|
|
30 data['pyvar'] = 123
|
|
31 for data['pycounter'] in range(60):
|
|
32 s.sensorupdate(data)
|
|
33
|