Alex Glow
Created February 16, 2018

The Habit Breaker

Use this little device to psych yourself into better habits! Like Green Lantern's ring and the Arc Reactor in one.

65
The Habit Breaker

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
3.7 V LiPo Battery
×1

Story

Read more

Code

"For real" code – importable into Adafruit editor

JavaScript
Here's a plain-text version you can paste directly into https://makecode.adafruit.com/#editor :)
let ke = 0
let list: number[] = []
let temp = 0
let item = 0
input.buttonA.onEvent(ButtonEvent.Click, function () {
    for (let item2 = 0; item2 <= 9; item2++) {
        if (list[item2]) {
            light.setPixelColor(9 - item2, 0x33ccff)
        } else {
            light.setPixelColor(9 - item2, 0x000000)
        }
    }
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    temp = 1
})
input.buttonsAB.onEvent(ButtonEvent.Click, function () {
    light.showRing(
    `white white white white white white white white white white`
    )
    loops.pause(500)
    light.showAnimation(light.sparkleAnimation, 500)
})
item = 0
light.showAnimation(light.sparkleAnimation, 500)
light.setAll(0x000000)
loops.forever(function () {
    loops.pause(5629500)
    temp = 0
    music.playSound(music.sounds(Sounds.PowerUp))
    light.setPixelColor(9 - ke, 0xffff00)
    loops.pause(120000)
    if (temp) {
        light.setPixelColor(9 - ke, 0x33ccff)
        list[ke] = 1
    } else {
        light.setPixelColor(9 - ke, 0x000000)
        list[ke] = 0
    }
    for (let item3 = 0; item3 <= 9; item3++) {
        if (list[item3]) {
            light.setPixelColor(9 - item3, 0x33ccff)
        } else {
            light.setPixelColor(9 - item3, 0x000000)
        }
    }
    loops.pause(10000)
    light.setAll(0x000000)
    ke += 1
    light.showAnimation(light.sparkleAnimation, 500)
    light.setAll(0x000000)
})

"For real" code – upload to board

JavaScript
Slower, and with annoying noises. :) Goes off about every 1.6 hours.
No preview (download only).

Demo code – upload to board

JavaScript
This is the demo code (super accelerated and with no sound), for testing.
No preview (download only).

Credits

Alex Glow

Alex Glow

145 projects • 1571 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.

Comments