-
Notifications
You must be signed in to change notification settings - Fork 0
/
EV3Dev Example Python Scripts.txt
86 lines (56 loc) · 1.91 KB
/
EV3Dev Example Python Scripts.txt
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
EV3Dev Example Python Scripts
EV3 and NXT Large Motors
import ev3dev.ev3 as ev3
m = ev3.LargeMotor('outA')
m.run_timed(speed_sp=300, time_sp=1000)
EV3 Medium Motors
import ev3dev.ev3 as ev3
m=ev3.MediumMotor ('outA')
m.run_timed(speed_sp=300, time_sp=1000)
RCX and Powerfunctions Motors
On the EV3 brick Select - Device Browser - Ports - ev3-ports:outA - Set mode - dc-motor
import ev3dev2.motor as ev3
m = ev3.DcMotor('outA')
m.run_timed(time_sp=3000, duty_cycle_sp=100)
EV3 and NXT Touch Sensors
import ev3dev.ev3 as ev3
ts = ev3.TouchSensor()
ts.connected
print(ts.value())
EV3 Ultrasonic Sensor
import ev3dev.ev3 as ev3
us = ev3.UltrasonicSensor ('in1')
us.mode = 'US-DIST-CM'
print(us.value(), "mm")
EV3 Gyro Sensor
import ev3dev.ev3 as ev3
gy = ev3.GyroSensor('in1')
print(gy.value())
EV3 Color Sensor
import ev3dev.ev3 as ev3
cs = ev3.ColorSensor('in1')
cs.mode = 'COL-COLOR'
print(cs.value())
NXT Ultrasonic Sensor
import ev3dev.ev3 as ev3
us = ev3.UltrasonicSensor('in1')
us.mode = 'US-DIST-CM'
print(us.value(), "cm")
EV3 Infrared Sensor
import ev3dev.ev3 as ev3
ir = ev3.InfraredSensor('in1')
ir.mode = 'IR-PROX'
print(ir.value())
NXT Light Sensor
import ev3dev.ev3 as ev3
l = ev3.LightSensor('in1')
l.mode = 'AMBIENT'
print(l.value())
NXT Sound Sensor
On the EV3 brick Select - Device Browser - Ports - ev3-ports:in1 - Set device - lego-nxt-sound
And Select - Device Browser - Ports - ev3-ports:in1 - Set mode - nxt-analog
import ev3dev.ev3 as ev3
s = ev3.SoundSensor('in1')
print(s.value())
For more detailed information on sensor modes and motor control functions as well as other types of supported sensors and motors see the link below:
http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-jessie/sensors.html