Gesture Loop Sample
This sample demonstrates detecting hand gestures.
- 1.Download the sample code from https://github.com/Turta-io/IoTHAT3/blob/master/Samples/Python/Gesture_Loop.py
- 2.Copy the sample code to a folder on the Raspberry Pi.
- 3.Open terminal, and then go to the folder you copied the sample.
- 4.Run the sample with the following command:
python3 Gesture_Loop.py
Gesture_Loop.py
#!/usr/bin/env python3
#This sample demonstrates detecting hand gestures.
#Install IoT HAT 3 library with "pip3 install turta-iothat3"
from time import sleep
from turta_iothat3 import Turta_Light
from turta_iothat3 import Turta_Buzzer
#Initialize
light = Turta_Light.LightSensor(Turta_Light.MODES.PROX_GES)
buzzer = Turta_Buzzer.BuzzerDriver()
try:
while True:
#Check gestures
g = light.read_gesture()
if g is not None:
print("Gesture Detected: " + str(g))
buzzer.beep()
#Wait
sleep(0.05)
#Exit on CTRL+C
except KeyboardInterrupt:
print('Bye.')
When you run the sample, it looks for a gesture data in every loop. When it detects one, prints the direction. The example output should be like this:
Gesture Detected: GESTURES.LEFT
Gesture Detected: GESTURES.RIGHT
Gesture Detected: GESTURES.UP
Gesture Detected: GESTURES.DOWN
To stop the Python script, just press CTRL + C.
Last modified 3yr ago