bit:bot 遥控器

micro:bit编程、教学、展示
STEM
回复
头像
shaoziyang
帖子: 363
注册时间: 2019年 10月 21日 13:48

bit:bot 遥控器

#1

帖子 shaoziyang » 2019年 11月 7日 23:03

转自:https://ukbaz.github.io/howto/bitbotRemoteControl.html
DIY一个bit:bot小车的蓝牙遥控器

On Startup
It is always nice to have a message display on startup so you know you have the correct program loaded up. E.g.
图片

On Bluetooth Connection
Set pins to a known state and display a message so you know the connection has been successful
图片

On Bluetooth Disconnection
When we disconnect then make sure everything is off and send a message to the user
图片

Buzzer
We can capture when buttons are pressed and released. We will make the buzzer turn on when button 4 is pressed and turn off when button 4 is released.
When button 4 is pressed we do an analog write to pin 14 to make the buzzer sound.
图片

Move Forward
We are going to code up that when button A is pressed we will move forward and when it is released the robot will stop. This is not the only way of doing it but a nice straight forward way for this tutorial.
To move forward we need to set pins 1 and 0 high while pins 12 and 8 are low. We do this when the button A is pressed and all pins are low when the button is released.
图片

Move Backwards
Button B is going to move the robot backwards and to do this we reverse which pins are high. This means that pins 12 and 8 are high. Same as last time, to stop the robot on releasing the button we set all pins to low.
图片

Spin Left
Button C is going to make the robot spin left. We do this by making only the right motor move forwards.
图片

Spin Right
Finally button D is going to spin the robot right and we do this by just rotating the left motor forwards.
图片Project Settings图片

回复