Värianturin lukeminen

From cod3v
Revision as of 06:33, 23 September 2020 by Mol (talk | contribs) (Created page with "== Esimerkki ==")
Other languages:
English • ‎suomi

Johdanto

Jotta saat kaiken hyödyn antureistasi, ne täytyy tuntea. Tässä esimerkissä testataan lukemia erilaisilla pinnoilla ja materiaaleilla.

Robotti

Ideat ja periaatteet toimivat lähes kaikille roboteille, mutta tämä on testattu Asimovilla.

Anturit

Värianturia käytetään reflected light intensity -moodissa, eli heijastuneen valon tilassa.

Esimerkki

Theory

To read the sensor is easy, but printing the value on a screen with a large enough font is intresting. Note that the print() -command works exactly as Python's print. There is a possibility to use Ev3-G like display command. It is shown elsewhere.

An Example Code

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

#Sensor port convention:
#port 3 = color
#port 1 = touch, port 2 = gyro, port 3 = color, port 4 = infrared or ultrasonic.

from ev3dev2.sensor.lego import ColorSensor

from time import sleep
import os

os.system('setfont Lat15-TerminusBold14')  #Too small for my eyes!
os.system('setfont Lat15-TerminusBold32x16')  # Try this larger font
cl = ColorSensor() 

cl.calibrate_white()

while True:
    print(cl.reflected_light_intensity) 
    sleep(1)

#84 is Max
#30 is Min

Exercises

1. Make a table of the reflectance of different colors and materials.

About

This course is supported by Meet and Code. The course is made in collaboration with Robotiikka- ja tiedekasvatus ry.

MeetAndcodeLogo.png


Meet and Code II: Python