RC car lesson (#519)

* initial drop

* fixing summary

* adding images

* Adding basic connect code

* connect section

* moving video

* adding ignores
This commit is contained in:
Peli de Halleux
2017-08-25 17:02:13 -07:00
committed by GitHub
parent 588f127ddd
commit 743979b9ea
17 changed files with 261 additions and 0 deletions

View File

@ -0,0 +1,54 @@
# Connect
https://youtu.be/XXesoUC0XBU
We are going to use radio to remote control the toy car.
A second @microbit@ will send commands to control the throttle and the steering.
```blocks-ignore
let steering = 0
let throttle = 0
radio.onDataPacketReceived( ({ receivedString: name, receivedNumber: value }) => {
led.toggle(0, 0)
if (name == "throttle") {
if (value > 0) {
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100);
} else if (value < 0) {
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Forward, 100);
} else {
kitronik.motorOff(kitronik.Motors.Motor1);
}
} else if (name == "steering") {
if (value > 0) {
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100);
} else if (value < 0) {
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Reverse, 100);
} else {
kitronik.motorOff(kitronik.Motors.Motor2);
}
}
})
basic.forever(() => {
throttle = 0
if (input.buttonIsPressed(Button.A)) {
throttle = 100
} else if (input.buttonIsPressed(Button.B)) {
throttle = -100
}
radio.sendValue("throttle", throttle)
steering = 0
if (input.acceleration(Dimension.X) < -512) {
steering = -100
} else if (input.acceleration(Dimension.X) > 512) {
steering = 100
}
radio.sendValue("steering", steering)
})
radio.setGroup(12)
```
```package
radio
pxt-kitronik-motor-driver=github:kitronikltd/pxt-kitronik-motor-driver#v0.0.3
```