Used Grove Moduls :
- Ultrasonic Ranger
- Speaker
- LED Strip
and Raspberry Pi as Wio Server
Python Script:
import requests
import time
if __name__ == '__main__':
url_range = 'http://192.168.38.58:8080/v1/node/GroveUltraRangerD1/range_in_cm?access_token=9164e46e6c460b57b711ac90eca626b9'
response = requests.get(url_range)
range_cm = response.json()['range_cm']
leds = int(0)
while range_cm > 5 :
leds_old = leds
leds = int(range_cm / 10)
if leds > 20 :
leds = 20
if leds <> leds_old :
rgb = ''
rgbs = int(0)
while rgbs < 20 :
rgbs += 1
if rgbs <= leds :
if leds < 5 :
rgb += '110000'
else :
rgb += '001100'
else :
rgb += '000000'
url_leds = 'http://192.168.38.58:8080/v1/node/GroveLedWs2812D0/segment/0/' + rgb + '?access_token=9164e46e6c460b57b711ac90eca626b9'
requests.post(url_leds)
print(range_cm, leds)
if leds < 2 :
url_beep = 'http://192.168.38.58:8080/v1/node/GroveSpeakerD2/sound_ms/1000/200?access_token=9164e46e6c460b57b711ac90eca626b9'
requests.post(url_beep)
elif leds < 3 :
url_beep = 'http://192.168.38.58:8080/v1/node/GroveSpeakerD2/sound_ms/800/200?access_token=9164e46e6c460b57b711ac90eca626b9'
requests.post(url_beep)
elif leds < 4 :
url_beep = 'http://192.168.38.58:8080/v1/node/GroveSpeakerD2/sound_ms/600/200?access_token=9164e46e6c460b57b711ac90eca626b9'
requests.post(url_beep)
elif leds < 5 :
url_beep = 'http://192.168.38.58:8080/v1/node/GroveSpeakerD2/sound_ms/400/200?access_token=9164e46e6c460b57b711ac90eca626b9'
requests.post(url_beep)
response = requests.get(url_range)
range_cm = response.json()['range_cm']
time.sleep(.5)
url_leds = 'http://192.168.38.58:8080/v1/node/GroveLedWs2812D0/clear/35/000000?access_token=9164e46e6c460b57b711ac90eca626b9'
requests.post(url_leds)
print("End")
Video:
[youtube]https://www.youtube.com/watch?v=9w6bnPXLrnQ[/youtube]