Last active
August 8, 2020 15:47
-
-
Save tyleretters/65ff1a1c11f881eb240924781f5c320e to your computer and use it in GitHub Desktop.
norns microstudy - short & long press
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
screen_dirty = true | |
function init() | |
counter = {} | |
message = "welcome to microstudy" | |
press_length_in_seconds = 1 | |
for k = 1,3 do | |
counter[k] = {} | |
end | |
clock.run(screen_redraw_clock) | |
redraw() | |
end | |
function key(k,z) | |
if z == 1 then | |
counter[k] = clock.run(long_press,k) | |
elseif z == 0 then | |
if counter[k] then -- long press still waiting | |
clock.cancel(counter[k]) | |
short_press(k) | |
end | |
end | |
end | |
function long_press(k) | |
clock.sleep(press_length_in_seconds) | |
counter[k] = nil -- set this to nil so key-up doesn't trigger a shortpress | |
message = "long press: k" .. k | |
screen_dirty = true | |
end | |
function short_press(k) | |
message = "short press: k" .. k | |
screen_dirty = true | |
end | |
function redraw() | |
screen:clear() | |
screen.level(15) | |
screen.move(0, 32) | |
screen.text(message) | |
screen:update() | |
end | |
function screen_redraw_clock() | |
while true do | |
if screen_dirty then | |
redraw() | |
screen_dirty = false | |
end | |
clock.sleep(1/30) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment