SciJoy
Published

Circuit Playground Sunflower Looking for Light

This flower reads the brightness level. When the level dips below a threshold, a servo moves the flower in search of a bright spot.

BeginnerFull instructions provided2 hours860
Circuit Playground Sunflower Looking for Light

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
4xAA battery holder
4xAA battery holder
You just need a battery to power the CPE board. It doesn't have to be this one.
×1
Adafruit Servo
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Schematics

Wiring Diagram

Code

The comment section has the link to the MakeCode version. The code box is JavaScript.

JavaScript
https://makecode.com/_ekoWdr3wk5ry
let degrees = 0
let direction = 0
forever(function () {
    if (degrees == 40) {
        direction = 0
    }
    if (degrees == 120) {
        direction = 1
    }
    if (input.lightLevel() < 40 && direction == 0) {
        light.showRing(
        `blue blue blue blue blue purple purple purple purple purple`
        )
        degrees += 2
        pins.A1.servoWrite(degrees)
    } else if (input.lightLevel() < 40 && direction == 1) {
        light.showRing(
        `purple purple purple purple purple blue blue blue blue blue`
        )
        degrees += -2
        pins.A1.servoWrite(degrees)
    } else {
        light.showRing(
        `yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow`
        )
    }
})

Credits

SciJoy

SciJoy

7 projects • 15 followers
We run a YouTube channel where we share what we are learning and building with others.

Comments