2017-01-31 17:29:25 +01:00
|
|
|
# Code
|
2017-09-07 22:42:08 +02:00
|
|
|
## @description code to make the coffee cup monster alive
|
2017-01-31 17:29:25 +01:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~avatar avatar
|
2017-01-31 17:29:25 +01:00
|
|
|
|
|
|
|
Add code to open the mouth when light is detected.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|
2017-01-31 17:29:25 +01:00
|
|
|
|
|
|
|
## Duration: ~30 minutes
|
|
|
|
|
|
|
|
We are going to add code to open the mouth proportionally to the amount of light on the @boardname@.
|
|
|
|
In a loop, we will read the light and map it to an angle using the ``pins.map`` function.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
|
|
|
pins.servoWritePin(AnalogPin.P0, pins.map(
|
|
|
|
input.lightLevel(),
|
|
|
|
0,
|
|
|
|
255,
|
|
|
|
30,
|
|
|
|
150
|
|
|
|
))
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~button /projects/light-monster/connect
|
2017-01-31 17:29:25 +01:00
|
|
|
NEXT: Connect
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|