Lab 02: Robot Brain

My partner and I wanted to take inspiration from nocturnal animals, playing with the sensitivity to light and sound. We originally decided that the robot should react accordingly to a sudden increase in light or noise. 

Our Sketch:

The plan was to have the robot start off moving in random directions, but stop in the presence of bright light. In response to loud noises, we wanted it to display a certain pattern of lights, and shake. If an object comes too close to the robot, it will increase the distance between the object and itself, through the use of the proximity sensor. 

Because we did not have the proximity sensor or a buzzer (for the shaking effect), we wanted to represent the behavior using lights. We utilized the built in photocell in the microbit to measure the light level.

Our Code:

let light = 0

basic.showNumber(input.lightLevel())

light = input.lightLevel()

if (light < 20) {

   basic.showIcon(IconNames.Heart)

}

if (light > 20) {

   basic.showNumber(IconNames.Sad)

}

The microbit displayed a heart icon during low light conditions, and a sad face during increased light conditions. However, there were some issues with the photocell detecting light levels, so in the code below, we edited the sad face function to display the number for the light intensity. 

Our Edited Code: 

basic.showNumber(input.lightLevel())

let light = input.lightLevel()

if (light < 20) {

   basic.showIcon(IconNames.Heart)

}

if (light > 20) {

   basic.showNumber(input.lightLevel())

}

Leave a Reply