'How to send continuous radio signals in micro:bit?
I'm trying to make a remote controlled car with a camera. I need to send radio signals constantly which depending on the message sent will do certain things. I should have to hold down the buttons on the controller to execute the code. When no button is held I need to reset the steering and the camera should go down (there is a button for it to go up). How can I send continuous radio signals to update? The micro:bit is a V2 model. We're using DF-Driver and Kitronik Game Controller.
Here's my current code:
Kitronik_Game_Controller.onButtonPress(Kitronik_Game_Controller.ControllerButtonPins.Fire1, Kitronik_Game_Controller.ControllerButtonEvents.Down, function () {
radio.sendString("S")
})
Kitronik_Game_Controller.onButtonPress(Kitronik_Game_Controller.ControllerButtonPins.Fire2, Kitronik_Game_Controller.ControllerButtonEvents.Down, function () {
radio.sendString("CU")
})
Kitronik_Game_Controller.onButtonPress(Kitronik_Game_Controller.ControllerButtonPins.Down, Kitronik_Game_Controller.ControllerButtonEvents.Down, function () {
radio.sendString("B")
})
input.onButtonPressed(Button.A, function () {
radio.sendString("CL")
})
Kitronik_Game_Controller.onButtonPress(Kitronik_Game_Controller.ControllerButtonPins.Up, Kitronik_Game_Controller.ControllerButtonEvents.Down, function () {
radio.sendString("F")
})
radio.onReceivedString(function (receivedString) {
if (receivedString == "CL" && domeServoHorizontalAngle > 0) {
domeServoHorizontalAngle += -5
}
if (receivedString == "CR" && domeServoHorizontalAngle < 180) {
domeServoHorizontalAngle += 5
}
if (receivedString == "S") {
motor.motorStopAll()
}
if (receivedString == "CU" && domeServoVerticalAngle < 180) {
domeServoVerticalAngle += 5
} else {
if (domeServoVerticalAngle > 0) {
domeServoVerticalAngle += -5
}
}
if (receivedString == "F") {
motor.MotorRun(motor.Motors.M1, motor.Dir.CCW, 255)
}
if (receivedString == "B") {
motor.MotorRun(motor.Motors.M1, motor.Dir.CW, 255)
}
if (receivedString == "L") {
motor.servo(motor.Servos.S1, 135)
} else {
if (receivedString == "R") {
motor.servo(motor.Servos.S1, 45)
} else {
motor.servo(motor.Servos.S1, 90)
}
}
motor.servo(motor.Servos.S3, 180 - domeServoHorizontalAngle)
motor.servo(motor.Servos.S2, 180 - domeServoVerticalAngle)
})
input.onButtonPressed(Button.B, function () {
radio.sendString("CR")
})
Kitronik_Game_Controller.onButtonPress(Kitronik_Game_Controller.ControllerButtonPins.Right, Kitronik_Game_Controller.ControllerButtonEvents.Down, function () {
radio.sendString("R")
})
Kitronik_Game_Controller.onButtonPress(Kitronik_Game_Controller.ControllerButtonPins.Left, Kitronik_Game_Controller.ControllerButtonEvents.Down, function () {
radio.sendString("L")
})
let domeServoVerticalAngle = 0
let domeServoHorizontalAngle = 0
domeServoHorizontalAngle = 90
domeServoVerticalAngle = 90
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
