Skip to content

Commit

Permalink
cycle through 1-99 for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Sep 19, 2023
1 parent 521bb75 commit bb1b72e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion robot/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// configure group using button A, cycle through groups 1-9
// configure group using button A/B, cycle through groups 1-99
input.onButtonPressed(Button.A, () => {
microcode.previousGroup()
})
input.onButtonPressed(Button.B, () => {
microcode.nextGroup()
})

Expand Down
14 changes: 12 additions & 2 deletions robot/radio.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
namespace microcode {
const MAX_GROUPS = 100
let group = 1
radio.setGroup(group)

export function previousGroup() {
setGroup(group === 1 ? MAX_GROUPS - 1 : group - 1)
}

export function nextGroup() {
group = (group + 1) % 99
if (group === 0) group = 1
setGroup(group === MAX_GROUPS - 1 ? 1 : group + 1)
}

export function setGroup(newGroup: number) {
if (newGroup < 0)
newGroup += MAX_GROUPS
group = newGroup % MAX_GROUPS
radio.setGroup(group)
showRadioStatus()
}
Expand Down

0 comments on commit bb1b72e

Please sign in to comment.