If you saw the videotutorial on servomotors, you might have wondered how the mini servos were programmed to do the little dance at the end of the video. In this entry, you will learn how to program the movements using bitbloq blocks.
Creating a function to move servos:
To start off, we will create a function with this block, which we will rename as MePasoElDiaBailando (I spend the day dancing):
Then we will add a full entry parameter (int) which will be the data with the position that we want the mini servos to reach. We will pass this data to it from the main loop:
In order to move a mini servo connected to digital pin 3, the bitbloq block would keep the following form:
As you can see, we have set it on a 150 millisecond pause, so that the program waits a little while doing nothing while this servo is moving.
Let´s connect 8 mini servos! Yes, yes and YES! You can connect 8 servomotors on the ZUM BT-328 board without any problems:
NB: If you notice that the computer´s USB current isn´t enough to move this many servos, use an external power source or batteries to supply power to the controller board.
The dancing function for the eight servos would remain as long:
On the main loop, we will declare a local variable called pos which will be the angle that the mini servos take. To get started, we will tell them to take an angle of 20 degrees, passing this data to the MePasoElDiaBailando () function created:
After a delay of 500 milliseconds, we will programme a movement in the opposite direction, for example at an angle of 160 degrees:
The mini servos will then move in synchronisation, one by one, with 150 ms between each one. First until angle 20, wait 500 ms, then until the angle 160 and another half-second pause. The program remains like this until the end:
So now you know how the simple dance works, have a go at tweaking the pauses, synchronisation times and angles to personalise your dance. For example, would you be able to adjust these parameters using a potentiometer?