PROGRAMAR SENSORS
Sensor infrarojos
El motor funciona sempre fins quan detecta un objecte a una distancia inferior a
5 cm
Sensor.SetMode(4, 0) no cal
Motor.Start ("AD",25) posar en marxa el motor indefinidament
While "True"
raw = Sensor.ReadRaw(4,1)
ReadRaw(4,1) l1 indica llegir la matriu raw[0]
If (raw[0] < 50) Then
quan detecta un objecte a una distancia inferior a 50 mm
(5 cm)
Motor.Stop("AD","True") atura el motor
EndIf
EndWhile
ReadRaw(port, matriu) el parmetre matriu indica quants elements t aquesta matriu, pel sensor de distancia amb 1 en tenim
prou, ja que llegeix la distancia noms.
Sensor Giroscopi
El motor funciona sempre fins quan detecta que el sensor a girat ms 90 graus
Sensor.SetMode(2,0) el 2 s el port i el 0 s el mode que vol dir llegir en graus
While (Sensor.ReadRawValue(2,0) < 90)
Motor.Start ("AD",25)
EndWhile
Motor.Stop("AD","True")
Sensor de contacte
El motor A i D funcionen mentre no es prem el sensor de contacte
Sensor.SetMode(3,0) el 3 s el port i el 0 s el mode que vol dir llegir 100=premut 0=no
premut
While (Sensor.ReadPercent(3) <> 100)
Motor.Start ("AD",25)
EndWhile
Motor.Stop("AD","True")
Sensor de color
lassignaci
El motor A i B funcionen fins que detecta el color
negre de colors s:
1
Sensor.SetMode(3,2) el 3 s el port i el 2 s el mode
="BLACK"
Motor.Start ("AD",25)
2 ="BLUE"
While (Sensor.ReadRawValue(3,0) <> 1)
3
="GREEN"
4
="YELLOW
"
EndWhile
Motor.Stop("AD","True")
Sensor Appendix
Use ReadRawValue(port number, index) if you need to obtain a single nonpercentage value, such as a color code. The index value for ReadRawValue should
normally be zero except if you need to obtain value1 or value2 from the sensor, as
shown in the table below.
EV3 Sensors
Mode Name
0
TOUCH
Get reading
with
ReadPercent
Returns
0=not pressed, 100=pressed
0
1
2
COL-REFLECT
COL-AMBIENT
COL-COLOR
RGB-RAW
0
1
US-DIST-CM
US-DIST-IN
ReadRawValue
ReadRawValue
distance in mm
distance in inch
0
1
GYRO-ANG
GYRO-RATE
ReadRawValue
ReadRawValue
angle in degrees(**)
rate of change of angle in deg/s
0
1
IR-PROX
IR-SEEK
IR-REMOTE
NXT Sensors
Type
Mod
Name
e
NXT-TOUCH
Get reading
with
ReadPercent
Returns
0=not pressed, 100=pressed
4
4
4
0
NXT-REFLECT
1
NXT-AMBIENT
2**** NXT-COLOR
ReadPercent
ReadPercent
ReadRawValue
ReadRawValue
distance in cm
NXT-US-CM