Skip to content

Commit

Permalink
Fix remote control blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
CleoQc committed Jul 8, 2019
1 parent c98db07 commit 46291c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,24 @@ This is a quick and rewarding project! You can control your Gigglebot by using a

Use a second micro:bit as a remote control for your Gigglebot. Moving the remote hand-held microbit will control the Gigglebot.
On this micro:bit, put the following code:
(note that the group number must be the same between remote and GiggleBot, and each pair must have a unique number)

```blocks
basic.forever(() => {
remote.remoteControl(1)
remote.setGroup(1)
basic.forever(function () {
remote.remoteControl()
})
```

#### On your gigglebot's microbit #remote-onremotecontrol
#### use the following blocks #remote-remotecontrolaction

On the gigglebot's micro:bit, put this code:

(note that the group number must be the same between remote and GiggleBot, and each pair must have a unique number)
```blocks
remote.onRemoteControl(1, () => {
remote.setGroup(1)
remote.onRemoteControl(function () {
remote.remoteControlAction()
})
```
Expand All @@ -101,5 +105,3 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
## Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.


14 changes: 11 additions & 3 deletions giggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ namespace lights {
}
}
//% weight=97 color=#46BFB1 icon="\uf0d1"

//% groups='["other", "Both Remote and GiggleBot:", "Remote Controller:", "GiggleBot:"]'
namespace remote {

let radio_id = -1
/**
* Use this block in the 'on Start' sequence.
* In order to have a remote micro:bit control the GiggleBot, both of them
* must be in the same radio group - or remote group. You can use either this
* block or the "radio set group" block found under Radio.
Expand All @@ -158,8 +160,10 @@ namespace remote {
//% blockId="gigglebot_remote_set_group"
//% block="set remote group %id"
//% weight=99
//% group="Both Remote and GiggleBot:"
export function setGroup(id: number): void {
radio.setGroup(id)
radio_id = id
}

/**
Expand All @@ -171,6 +175,7 @@ namespace remote {
//% blockId="gigglebot_remote_control"
//% block="external remote controller"
//% weight=99
//% group="Remote Controller:"
export function remoteControl(): void {
let powerLeft = gigglebot.leftPower()
let powerRight = gigglebot.rightPower()
Expand Down Expand Up @@ -209,7 +214,8 @@ namespace remote {
*/
//% weight=98
//% blockId=gigglebot_remote block="remotely controlled gigglebot" blockGap=16
//% useLoc="radio.onDataPacketReceived" draggableParameters=reporter
//% useLoc="radio.onDataPacketReceived" draggableParameters=reporter
//% group="GiggleBot:"
export function onRemoteControl(cb: () => void) {
remote_init();
control.onEvent(DAL.MICROBIT_ID_RADIO, radio.MAKECODE_RADIO_EVT_BUFFER, () => {
Expand All @@ -218,14 +224,16 @@ namespace remote {
}

/**
* @param
* Put this block inside of the 'remotely controlled gigglebot' to follow all comands received via remote control.
*/
//% blockId="gigglebot_remote_control_action"
//% block="do remote control action"
//% weight=97
//% group="GiggleBot:"
export function remoteControlAction(): void {
let powerLeft = lastPacket.bufferPayload.getNumber(NumberFormat.Float32BE, 0);
let powerRight = lastPacket.bufferPayload.getNumber(NumberFormat.Float32BE, 4);

gigglebot.setLeftPower(powerLeft)
gigglebot.setRightPower(powerRight)
gigglebot.motorPowerAssignBoth(gigglebot.leftPower(), gigglebot.rightPower())
Expand Down

0 comments on commit 46291c5

Please sign in to comment.