Anda di halaman 1dari 3

EV3 + Small Basic

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 ReadPercent(port number) to obtain a single value in the range 0-100.

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=no reflected light, 100=max


ReadPercent
0=no ambient light, 100=max
ReadPercent
0=unknown, 1=black, 2=blue,
ReadRawValue
3=green, 4=yellow, 5=red,
6=white, 7=brown
value0=red intensity,
ReadRaw (3 vals) value1=green intensity,
value2=blue intensity

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

distance in cm (not very accurate)


ReadRawValue
value0=direction to IR beacon
ReadRaw (2 vals)
value1=distance to IR beacon
value0=signal from channel 1 (*),
ReadRawValue***
value1=signal from channel 2...

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

0=no reflected light, 100=max


0=no ambient light, 100=max
1=black, 2=blue, 3=green,
4=yellow, 5=red, 6=white

ReadRawValue

distance in cm

NXT-US-CM

Anda mungkin juga menyukai