Stephen Barrett
Published

Swedish mood lamp

I created a mood lamp with the circuit playground express and a ikea lamp.

BeginnerFull instructions provided1 hour561
Swedish mood lamp

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Alligator Clips
Alligator Clips
×1
Rechargeable Battery, Lithium Ion
Rechargeable Battery, Lithium Ion
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Toggle Switch, (On)-Off-(On)
Toggle Switch, (On)-Off-(On)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Code

Code for playground express in a cyan color

JavaScript
This is the code for the board to project a cyan blue color combination. This color combination is one of the brightest the board is capable of.
pins.A1.setPull(PinPullMode.PullUp)
forever(function () {
    if (!(pins.A1.digitalRead())) {
        light.setAll(0x00ffff)
        light.setBrightness(255)
    } else {
        light.clear()
    }
})

updated code to switch between colors

JavaScript
add a potentionmeter
let value = pins.A3.analogRead()
pins.A1.setPull(PinPullMode.PullUp)
forever(function () {
    if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 0 && pins.A3.analogRead() <= 100)) {
        light.setAll(0x7f00ff)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 101 && pins.A3.analogRead() <= 200)) {
        light.setAll(0xff00ff)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 201 && pins.A3.analogRead() <= 300)) {
        light.setBrightness(255)
        light.setAll(0xff0080)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 301 && pins.A3.analogRead() <= 400)) {
        light.setAll(0xff0000)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 401 && pins.A3.analogRead() <= 500)) {
        light.setBrightness(255)
        light.setAll(0xff8000)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 501 && pins.A3.analogRead() <= 600)) {
        light.setAll(0xffff00)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 601 && pins.A3.analogRead() <= 700)) {
        light.setBrightness(255)
        light.setAll(0x00ff00)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 701 && pins.A3.analogRead() <= 800)) {
        light.setAll(0x00ffff)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 801 && pins.A3.analogRead() <= 900)) {
        light.setBrightness(255)
        light.setAll(0x007fff)
    } else if (!(pins.A1.digitalRead()) && (pins.A3.analogRead() >= 901 && pins.A3.analogRead() <= 2000)) {
        light.setAll(0x0000ff)
        light.setBrightness(255)
    } else {
        light.clear()
    }
})

Credits

Stephen Barrett

Stephen Barrett

3 projects • 0 followers

Comments