Another very simple car to test the servo motors. This one is rather minimalistic, the idea was to have (powered) wheels that could turn using the servo motors.
Here is the code (as before, this source code is NOT optimized! and heavily based on the sample makeblock code) :
#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
MeDCMotor motor1(M1);
MeDCMotor motor2(M2);
MeInfraredReceiver infraredReceiverDecode(PORT_4);
MeServo servoDriver1(PORT_1,DEV1);
MeServo servoDriver2(PORT_1,DEV2);
int rightturn = 65;
int straight = 90;
int leftturn = 115;
uint8_t motorSpeed = 100;
void setup()
{
infraredReceiverDecode.begin();
servoDriver1.begin();
servoDriver2.begin();
}
void loop()
{
if(infraredReceiverDecode.available())
{
switch(infraredReceiverDecode.read())
{
case IR_BUTTON_PLUS: servoDriver1.write(straight) ; servoDriver2.write(straight) ; motor1.run(-motorSpeed) ; motor2.run(-motorSpeed); break;
case IR_BUTTON_MINUS: servoDriver1.write(straight) ; servoDriver2.write(straight) ; motor1.run(motorSpeed) ; motor2.run(motorSpeed); break;
case IR_BUTTON_PREVIOUS: servoDriver1.write(leftturn) ; servoDriver2.write(rightturn) ; break;
case IR_BUTTON_NEXT: servoDriver1.write(rightturn); servoDriver2.write(leftturn); break;
case IR_BUTTON_PLAY: motor1.stop() ; motor2.stop() ; break;
default:break;
}
}
}
cheers,
paul