Nathaniel Green
Published

Rainbow Mood Lighting Lamp

This is a lamp that I made for DIG3602 with the Circuit Board Express, using a Switch and Potentiometer.

BeginnerFull instructions provided238
Rainbow Mood Lighting Lamp

Things used in this project

Hardware components

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

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Code

Potentiometer / Toggle Switch Javascript

JavaScript
This Script Functions for both the toggle switch and the potentiometer for my lamp, where A1 is connected to the switch, and A2 is connected to the potentiometer.
let value = pins.A2.analogRead()
pins.A1.setPull(PinPullMode.PullUp)
forever(function () {
    if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 0 && pins.A2.analogRead() <= 100)) {
        light.setAll(0x7f00ff)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 101 && pins.A2.analogRead() <= 200)) {
        light.setAll(0xff00ff)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 201 && pins.A2.analogRead() <= 300)) {
        light.setBrightness(255)
        light.setAll(0xff0080)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 301 && pins.A2.analogRead() <= 400)) {
        light.setAll(0xff0000)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 401 && pins.A2.analogRead() <= 500)) {
        light.setBrightness(255)
        light.setAll(0xff8000)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 501 && pins.A2.analogRead() <= 600)) {
        light.setAll(0xffff00)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 601 && pins.A2.analogRead() <= 700)) {
        light.setBrightness(255)
        light.setAll(0x00ff00)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 701 && pins.A2.analogRead() <= 800)) {
        light.setAll(0x00ffff)
        light.setBrightness(255)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 801 && pins.A2.analogRead() <= 900)) {
        light.setBrightness(255)
        light.setAll(0x007fff)
    } else if (!(pins.A1.digitalRead()) && (pins.A2.analogRead() >= 901 && pins.A2.analogRead() <= 2000)) {
        light.setAll(0x0000ff)
        light.setBrightness(255)
    } else {
        light.clear()
    }
})

Credits

Nathaniel Green
4 projects • 0 followers
Thanks to Stephen Barrett.

Comments