Museum at night¶
Museum at night is an international project that allows exploration of museums, galleries and heritage sites after hours. During this time there are many events, themed talks and immersive workshops late into the evening.
First LEGO toy was produced in 1932. In Denmark there is the LEGO Museum. Imagine that at night the toys become alive in the museum. They can speak and move. Film lovers know such cases - Museum at night or Toy Story present similar situations.
The aim of the lesson is to programme our robot to do something you want but only when it is dark around – at night.
Mathematical problem: arithmetic average.
Preparing For This Tutorial:¶
The LEGO Mindstorm EV3 Robot that coincides with this tutorial comes from building specific sections found in the LEGO Mindstorm Education Core Set building instructions. You will need to build the main body of the robot (I’ll refer to use the Base Unit), plus a color sensor directed up (to better see the light).
Lessons: Basic (all topics).
Exercise
Create a programme that will cause the robot to do something you want but only when it is dark around – at night.
Create a programme in which the colour sensor measures the intensity of ambient light. The programme should end after pressing any brick button.
Put down the results of your classmates when it is dark and when the light is on and calculate the arithmetic mean. Create a programme in which the robot asks you about the average and compare the intensity of light with this average and then write the message: light or dark.
Modify your programme such that your robot moves, says something or plays any music file, switches on the light on the brick and displays some eyes when the light is off and does nothing (or only snoring) and has sleeping eyes when it is dark around.
Theory¶
Mean (Arithmetic Mean, Average) - The sum of all the numbers in a list divided by the number of items in that list.
Short help on programming¶
Commands/functions needed for the exercise.
Library ev3dev2
#!/usr/bin/env python3
import the necessary libraries
from ev3dev2.button import Button
from ev3dev2.sensor.lego import \*
or from ev3dev2.sensor.lego import ColorSensor
from time import sleep
Property in the ColorSensor class Available settings mode
Example:
#!/usr/bin/env python3
COL-REFLECT 0-100 Reflected light. LED color: red
cl=ColorSensor()
COL-AMBIENT 0-100 Ambient light.
LED color: blue (dimly lit)
COL-COLOR 0-7
Color.
LED color: white
cl.mode='COL-AMBIENT'
RGB-RAW
Raw Color Components.
LED color: white
Function from Sensor class - Returns the value measured by the sensor value()
Example:
variable=cl.value()
cl denotes an instance of ColorSensor
Function in class Button. Checks any if any button is pressed.
Example:
#!/usr/bin/env python3
Btn=Button()
btn.any()
Helpful function for motors (for details see Module Motors)
#!/usr/bin/env python3
from ev3dev2.motor import LargeMotor
on(speed=<value>)
off()
sounds (for details see Module Sounds)
from ev3dev2.sound import Sound
play_file(path,volume=<value>)
for display and LEDs (for details see Module Display)
from ev3dev2.display import Display
clear()
draw.text((0,0),string)
update()
image.paste(im, (0,0))
im =Image.open(path) #file handling
for display and LEDs (for details see Module Display)
from ev3dev2.led import Leds
all_off()
set_color('LEFT', 'AMBER')
About class Leds, Display, Sound, Motors see Basics Modules.
Bibliography:
https://www.lego.com/en-us/aboutus/lego-group/the_lego_history