Vernier Acceleration Sensor Python: Difference between revisions

From wikiluntti
No edit summary
No edit summary
Line 3: Line 3:
=== Sensor Class: Check the modes ===
=== Sensor Class: Check the modes ===


Actually, the following codes assume that the color sensor is attached to the port 1.
Actually, the following codes assume that the color sensor is attached to the port 1. It should be "nxt-analog".


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
Line 13: Line 13:


import time
import time
import os
os.system('setfont Lat15-TerminusBold32x16')  # Try this larger font


p = Sensor( INPUT_1 )
p = Sensor( INPUT_1 )
Line 19: Line 21:
     time.sleep(5)
     time.sleep(5)
</syntaxhighlight>
</syntaxhighlight>
Returns the following modes 'ref-raw', 'rgb-raw' and 'col-cal'
Returns the following modes 'analog-0' and 'analog-1'.


Or equivalently the following code works
Or equivalently the following code works
Line 32: Line 34:
print( accSensor.modes )
print( accSensor.modes )
#time.sleep(5)
#time.sleep(5)
accSensor.mode="REF-RAW" #about 565, no changes
accSensor.mode="ANALOG-0"   #
#accSensor.mode="RGB-RAW" #about 121
#accSensor.mode="ANALOG-1" #
#accSensor.mode="COL-CAL" #Not working
#time.sleep(5)
#time.sleep(5)
while 1:
while 1:

Revision as of 20:05, 21 September 2020

Introduction

Sensor Class: Check the modes

Actually, the following codes assume that the color sensor is attached to the port 1. It should be "nxt-analog".

#!/usr/bin/env python3
# https://sites.google.com/site/ev3devpython/

from ev3dev2.sensor import *
from ev3dev2.sensor import INPUT_1

import time
import os
os.system('setfont Lat15-TerminusBold32x16')  # Try this larger font

p = Sensor( INPUT_1 )
while 1:
    print( p.modes )
    time.sleep(5)

Returns the following modes 'analog-0' and 'analog-1'.

Or equivalently the following code works

from ev3dev2.sensor import *

import time

accSensor = Sensor(address="ev3-ports:in1")
print( accSensor )
print( accSensor.modes )
#time.sleep(5)
accSensor.mode="ANALOG-0"   #
#accSensor.mode="ANALOG-1"  #
#time.sleep(5)
while 1:
    print(accSensor.value() )

but the values are not exactly proper.