My plan there was to just connect all four jumpers from the microbit to the analog input pins on the arduino. This turned out to be trivially easy, in the code i just run analogread() for each pin and if the input is above a threshold, assume it's a signal and do something.
Connecting microbit to Arduino analog input pins. |
const int pwmOutput = 255;
const int moveThreshold = 125; // how much of a signal before we trigger
// left
if (analogRead(leftFord) > moveThreshold){
moveLeftFord(pwmOutput);
} else if (analogRead(leftBack) > moveThreshold){
moveLeftBack(pwmOutput);
} else stopLeft();
This was probably the most time consuming element in the project. I wanted the vehicle to only move if you were holding the button down, otherwise stop that motor. I'd already tested and the microbit will happily accept multiple simultaneous commands, so we're all good.
So with the wires etc all bundled on top I drove around a bit and scared the cat :) job done, it's now just a matter of packaging it all up so that it's neat and tidy and kid proof. I should also add some fun factor in, and with four more potential inputs on the controller i could add some sounds or lights or a gatling gun.. whatever is the most enjoyable.. ;)
No comments:
Post a Comment