-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
}) |