Skip to content

Commit

Permalink
simplify rotary encoder sample
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 27, 2023
1 parent 8c5ba25 commit 3f59e09
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions tools/microbit-jukebox/rotaryencoder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
machine.addClientFactory(jacdac.SRV_ROTARY_ENCODER, (devid, srvid, options) => {
const clicks = 12
const client = new modules.RotaryEncoderClient(`${devid}:${srvid}`)
let currentPosition = client.position()
if (!currentPosition) currentPosition = 0
client.onPositionChanged(() => {
let clicks = client.clicksPerTurn()
clicks = clicks ? clicks : 24
const newPosition = client.position()
machine.microbit.emit(
currentPosition < newPosition ? machine.EVENT_A : machine.EVENT_B
)
currentPosition = newPosition
machine.plot(newPosition % clicks, clicks, options)
let currentPosition = 0
client.onPositionChanged(delta => {
machine.microbit.emit(delta > 0 ? machine.EVENT_A : machine.EVENT_B)
currentPosition += delta
machine.plot(currentPosition % clicks, clicks, options)
})
return client
})

0 comments on commit 3f59e09

Please sign in to comment.