-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicar.py
57 lines (47 loc) · 1.28 KB
/
picar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# PiCar Script
# This is intended for use with a guide located here:
# <ADD URL>
# Author: Stephen Garrison
from adafruit_crickit import crickit
import blynklib
# Add your blynk API key from the admin console or app
BLYNK_AUTH = 'ADD_API_KEY_HERE'
# The server is running on the same pi you're controlling
# no change needed here
blynk = blynklib.Blynk(BLYNK_AUTH, server='0.0.0.0', port='8080')
momo1 = crickit.dc_motor_1
momo2 = crickit.dc_motor_2
@blynk.handle_event('write V0')
def go_forward(pin, value):
if int(value[0]) == 1:
momo1.throttle = 1
momo2.throttle = 1
else:
momo1.throttle = 0
momo2.throttle = 0
@blynk.handle_event('write V1')
def go_back(pin, value):
if int(value[0]) == 1:
momo1.throttle = -1
momo2.throttle = -1
else:
momo1.throttle = 0
momo2.throttle = 0
@blynk.handle_event('write V2')
def turn_right(pin, value):
if int(value[0]) == 1:
momo1.throttle = -1
momo2.throttle = 1
else:
momo1.throttle = 0
momo2.throttle = 0
@blynk.handle_event('write V3')
def turn_left(pin, value):
if int(value[0]) == 1:
momo1.throttle = 1
momo2.throttle = -1
else:
momo1.throttle = 0
momo2.throttle = 0
while True:
blynk.run()