Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Sep 19, 2023
2 parents bae1600 + 522e673 commit e11457c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 24 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
## Microsoft MicroCode [https://aka.ms/microcode](https://aka.ms/microcode)

Microsoft MicroCode is an icon-based programming language and editor for young learners to code with the [BBC micro:bit V2](https://microbit.org). MicroCode runs in the browser or directly on the micro:bit V2 with an [Arcade shield accessory](#arcade-shields-for-microbit-v2).

## Happy/Sad program

Here's the classic micro:bit *Happy-A-button/Sad-B-button* program in MicroCode:
Microsoft MicroCode is an icon-based programming language and editor for young learners to code with the [BBC micro:bit V2](https://microbit.org). MicroCode allows you to program the micro:bit V2 with only an [Arcade shield accessory](#arcade-shields-for-microbit-v2) - *no other computer is required!* If you prefer the web browser, there's also a MicroCode web app that connects to your micro:bit V2 over WebUSB. Here's the classic micro:bit *Happy-A-button/Sad-B-button* program in MicroCode:

![MicroCode screenshot](./docs/images/generated/sample_smiley_buttons.png)

Expand Down
3 changes: 0 additions & 3 deletions robot/micromaqueenrobot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace microcode {
maqueen.motorRun(maqueen.Motors.All, right < 0 ? maqueen.Dir.CCW : maqueen.Dir.CW, right)
}
}
motorStop() {
maqueen.motorStop(maqueen.Motors.All)
}
}

robot = new MicroMaqqueenRobot()
Expand Down
4 changes: 1 addition & 3 deletions robot/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ namespace microcode {
const MESSAGE_MAGIC = 0xf498

export enum RobotCommand {
SetRobotDriver = 0x0001,
MotorRun = 0x0002,
MotorStop = 0x0003,
MotorRun = 0x0001,
}
export enum RobotDrivers {
MicroMaqqueen = 0x01
Expand Down
11 changes: 3 additions & 8 deletions robot/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace microcode {

export function setGroup(newGroup: number) {
if (newGroup < 0)
newGroup += MAX_GROUPS
newGroup += MAX_GROUPS
group = newGroup % MAX_GROUPS
radio.setGroup(group)
showRadioStatus()
Expand All @@ -40,17 +40,12 @@ namespace microcode {
const payload = msg.payload
switch (cmd) {
case RobotCommand.MotorRun: {
const left = payload.getNumber(NumberFormat.Int8LE, 0)
const right = payload.getNumber(NumberFormat.Int8LE, 1)
const left = Math.clamp(-255, 255, payload.getNumber(NumberFormat.Int16LE, 0))
const right = Math.clamp(-255, 255, payload.getNumber(NumberFormat.Int16LE, 2))
console.log(`motor run ${left} ${right}`)
robot.motorRun(left, right)
break
}
case RobotCommand.MotorStop: {
console.log(`motor stop`)
robot.motorStop()
break
}
}
})
}
7 changes: 2 additions & 5 deletions robot/robot.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
namespace microcode {
export interface Robot {
/*
Set the power on motors
Set the power on motors where `left` and `right` are in [-255,255]
Set left and right to 0 to stop.
*/
motorRun(left: number, right: number): void;
/**
* Stop and brake
*/
motorStop(): void;
}

export let robot: Robot
Expand Down

0 comments on commit e11457c

Please sign in to comment.