Now is a good time to get something to move with our board by connecting a servo. I directly go to the supplied SoftPWMServo library as it offer to run a servo ono any GPIO pin of the chip. In the example, I connect the servo to the pin 4 on the right side of the board:
The code is quite simple and straight forward:
const uint8_t LEFT=0;
const uint8_t RIGHT=1;
uint8_t nP[2][8] = {{0,17, 9,10,11,12,13,14},{18,17, 1, 2, 3, 6, 7, 8}};
#include <SoftPWMServo.h>
int pos = 0; // variable to store the servo position, in microseconds
const int pin = nP[RIGHT][3]; // Choose _any_ pin number on your board, i.e. pin 3, right side
void setup()
{
}
void loop()
{
for(pos = 1000; pos < 2000; pos += 10) // goes from 1ms to 2ms
{ // in steps of 10us
SoftPWMServoServoWrite(pin, pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
}
For a specific servo, it is useful to test to extend the range for the position to 500 - 2500 ms. I was surprised by the smoth movement of the servo compared to the normal servo lib I used in the Arduino setup.