Created
October 23, 2019 11:47
-
-
Save dbonates/345471cb9a9a3700662435484acf400a to your computer and use it in GitHub Desktop.
small snippet experimenting vibration motor and led on pico-8 games
This file contains hidden or 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
| function write_gpio_unsigned(num,pin_index,bits) | |
| local lastbit_i = | |
| 0x5f80+pin_index+bits-1 | |
| local mask = 1 | |
| for j=0,bits-1 do | |
| local bit = shr(band(num, mask), j) | |
| poke(lastbit_i-j, bit*255) | |
| mask = shl(mask, 1) | |
| end | |
| end | |
| function read_gpio_unsigned(pin_index,bits) | |
| local firstbit_i = | |
| 0x5f80+pin_index | |
| local num = 0 | |
| for j=0,bits-1 do | |
| local val = peek(firstbit_i+j) | |
| if val > 0 then | |
| num = num + shl(1, bits-1-j) | |
| end | |
| end | |
| return num | |
| end | |
| function _init() | |
| write_gpio_unsigned(0, 3, 8) | |
| x=64 | |
| y=64 | |
| last = time() | |
| end | |
| function _update() | |
| if (btn(⬅️)) x-=1 | |
| if (btn(➡️)) x+=1 | |
| if (btn(⬆️)) y-=1 | |
| if (btn(⬇️)) y+=1 | |
| if (btnp(❎)) vibra() | |
| if (time() - last) > 1/5 then | |
| write_gpio_unsigned(0, 3, 8) | |
| end | |
| end | |
| function vibra() | |
| last = time() | |
| write_gpio_unsigned(255, 3, 8) | |
| end | |
| function _draw() | |
| cls() | |
| map(0,0) | |
| spr(0,x,y) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment