Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let max = 0
- let base2exp = 0
- let n = 0
- let tick = 100 // refresh rate in milliseconds
- input.onButtonPressed(Button.A, () => {
- decrement()
- })
- input.onButtonPressed(Button.B, () => {
- increment()
- })
- function decrement() {
- if (n < 0) {
- n = max
- } else {
- n = n - 1
- }
- }
- function increment() {
- if (n > max) {
- n = 0
- } else {
- n += 1
- }
- }
- n = 0 // counter starts at zero
- base2exp = 30 //number of binary 'switches'
- max = 2 ** base2exp // 2^base2exp
- function dec2bin(dec: number) {
- let binN = (dec >>> 0).toString(/*should be able to pass in radix*/)
- basic.showString(binN)
- return binN
- }
- basic.forever(() => {
- basic.pause(tick)
- basic.showString(dec2bin(n))
- })
Advertisement
Add Comment
Please, Sign In to add comment