Stap 7: de software: arduino
de software bestaat uit twee delen: de arduino-kant en de kant van de computer. de arduino-kant is vrij eenvoudig, de code daarvoor is als volgt:
#include;
Servo lefttop;
Servo leftbottom;
Servo righttop;
Servo rightbottom;
int incomingByte;
VOID Setup
{
lefttop.attach(8);
leftbottom.attach(9);
righttop.attach(10);
rightbottom.attach(11);
lefttop.write(90);
leftbottom.write(90);
righttop.write(90);
rightbottom.write(90);
Serial.begin(9600);
}
void loop / / dit is werden de eigenlijke programma is tenslotte liep in een oneindige lus;
{
Als (Serial.available() > 0) {//check voor verbinding
incomingByte = Serial.read(); Als er gegevens beschikbaar lezen aan de variabele incomingByte
if(incomingByte=='f')
{
lefttop.write(0);
leftbottom.write(0);
righttop.write(180);
rightbottom.write(180);
}
if(incomingByte=='r')
{
lefttop.write(180);
leftbottom.write(180);
righttop.write(0);
rightbottom.write(0);
}
if(incomingByte=='R')
{
lefttop.write(180);
leftbottom.write(180);
righttop.write(180);
rightbottom.write(180);
}
if(incomingByte=='o')
{
lefttop.write(180);
leftbottom.write(180);
righttop.write(180);
rightbottom.write(180);
delay(250);
lefttop.write(90);
leftbottom.write(90);
righttop.write(90);
rightbottom.write(90);
}
if(incomingByte=='L')
{
lefttop.write(0);
leftbottom.write(0);
righttop.write(0);
rightbottom.write(0);
}
if(incomingByte=='u')
{
lefttop.write(0);
leftbottom.write(0);
righttop.write(0);
rightbottom.write(0);
delay(250);
lefttop.write(90);
leftbottom.write(90);
righttop.write(90);
rightbottom.write(90);
}
if(incomingByte=='s')
{
lefttop.write(90);
leftbottom.write(90);
righttop.write(90);
rightbottom.write(90);
}
}}