-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardware-test.py
87 lines (73 loc) · 2.2 KB
/
hardware-test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: UTF-8 -*-
import time
from pinpong.board import Board,Pin,Servo
from pinpong.libs.dfrobot_urm09 import URM09 #从libs中导入URM09库
Board("leonardo").begin() #初始化,选择板型(uno、leonardo、xugu)和端口号,不输入端口号则进行自动识别
urm = URM09(i2c_addr=0x11) #初始化传感器,设置I2C地址
urm.set_mode_range(urm._MEASURE_MODE_AUTOMATIC ,urm._MEASURE_RANG_500) #设置URM09模式为自动检测,最大测量距离500cm
pwm0 = Pin(Pin.D8, Pin.OUT)
pwm1 = Pin(Pin.D9,Pin.OUT)
acidpump = Servo(Pin(Pin.D11)) #将Pin传入Servo中初始化舵机引脚
alkalipump = Servo(Pin(Pin.D12)) #将Pin传入Servo中初始化舵机引脚
testpump = Servo(Pin(Pin.D13)) #将Pin传入Servo中初始化舵机引脚
def PumpTest():
alkalipump.write_angle(0)
time.sleep(2)
alkalipump.write_angle(90)
time.sleep(2)
alkalipump.write_angle(180)
time.sleep(2)
alkalipump.write_angle(90)
time.sleep(2)
print("alkali pump tested")
testpump.write_angle(0)
time.sleep(2)
testpump.write_angle(90)
time.sleep(2)
testpump.write_angle(180)
time.sleep(2)
testpump.write_angle(90)
time.sleep(2)
print("test pump tested")
acidpump.write_angle(0)
time.sleep(2)
acidpump.write_angle(90)
time.sleep(2)
acidpump.write_angle(180)
time.sleep(2)
acidpump.write_angle(90)
time.sleep(2)
print("acid pump tested")
return
def MoveTo():
D = input("input:")
d = int(D)
dist = urm.distance_cm()
if d >19 or d <= 2:
d= dist
while d - dist != 0:
dist = urm.distance_cm()
if d - dist > 0:
pwm0.write_digital(1)
pwm1.write_digital(0)
#time.sleep(0.1)
print("down",dist)
if d - dist < 0:
pwm0.write_digital(0)
pwm1.write_digital(1)
#time.sleep(0.1)
print("up",dist)
if d - dist == 0:
pwm0.write_digital(0)
pwm1.write_digital(0)
time.sleep(0.5)
print("stop",dist)
return
while True:
dist = urm.distance_cm() #读取距离数据,单位厘米(cm)
temp = urm.temp_c() #读取传感器温度,单位摄氏度(℃)
print("Distance is %d cm "%dist)
print("Temperature is %.2f .c "%temp)
time.sleep(0.5)
PumpTest()
MoveTo()