Skip to content

Commit

Permalink
wip bodychain
Browse files Browse the repository at this point in the history
  • Loading branch information
gufett0 committed Dec 6, 2024
1 parent 393ac20 commit d43313f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions classroom_code/embedded/bodychain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
let lastUpdateTime = 0
let wasPressed = false
let isPressed = false
// 100ms between updates
let UPDATE_INTERVAL = 100
basic.showString("Hi")
basic.forever(function () {
isPressed = input.pinIsPressed(TouchPin.P0)
// Handle button state changes immediately
if (isPressed && !(wasPressed)) {
// Button just pressed - show pressed pattern
basic.showLeds(`
# . . . #
. # # # .
. # # # .
. # # # .
# . . . #
`)
wasPressed = true
} else if (!(isPressed) && wasPressed) {
// Button just released - show released pattern and send release code
basic.showLeds(`
# . . . #
. # . # .
. . . . .
. # . # .
# . . . #
`)
serial.writeNumber(101)
wasPressed = false
}
// Only send random numbers if enough time has passed
if (isPressed && input.runningTime() - lastUpdateTime >= UPDATE_INTERVAL) {
serial.writeNumber(randint(0, 100))
lastUpdateTime = input.runningTime()
}
})

0 comments on commit d43313f

Please sign in to comment.