Skip to content

Commit

Permalink
updated wall events, display matching the value of d
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Sep 29, 2023
1 parent b7ebe1a commit 040b796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions robot/robotdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,24 @@ namespace microcode {
}
}

private lastSonarValue = 0
private showSonar() {
if (this.showRadio > 0) return

const dist = this.ultrasonicDistance()
this.log(`sonar dist`, dist)
// render sonar
if (dist > ULTRASONIC_MIN_READING) {
const d = Math.clamp(1, 5, Math.ceil(dist / 5))
for (let y = 0; y < 5; y++)
if (dist > 0 && dist < 5 + y * 5) led.plot(2, y)
if (y + 1 >= d) led.plot(2, y)
else led.unplot(2, y)

const d = Math.min(1, Math.max(5, Math.round(dist / 5)))
const msg = microcode.robots.RobotCompactCommand.Obstacle0 | d
microcode.robots.sendCompactCommand(msg)
if (d !== this.lastSonarValue) {
this.lastSonarValue = d
const msg = microcode.robots.RobotCompactCommand.Obstacle0 | d
microcode.robots.sendCompactCommand(msg)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion robot/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
microcode.elecfreaksCuteBot.start()
//microcode.yahboomTinyBit.start()
//microcode.keyStudioMiniSmartRobot.start()
microcode.setMotorDrift(0)
microcode.setMotorDrift(6)

microcode.robotDriver.motorRun(100)

Expand Down

0 comments on commit 040b796

Please sign in to comment.