Stap 7: Stap 7: tandriem installatie
Na het zetten van de tandriem, kunt u deze draad verbinden met uw BaseBoard.
In de laatste foto trok ik de batterijhouder zodat u mijn verbindingen zien kunt. Eigenlijk behoort de draad op poort 3 eigenlijk tot poort 6. U kunt het zien van mijn code.
Arduino code:
#include < Makeblock.h >
#include < Arduino.h >
#include < SoftwareSerial.h >
#include < Wire.h >
MeDCMotor Motor1(M1); De motor op uw derde wiel (met de richting motor)
MeDCMotor Motor2(PORT_2);
MeDCMotor Motor3(PORT_1);
MeDCMotor MotorDirection(M2); / / richting motor
MeInfraredReceiver infraredReceiverDecode(PORT_6);
int ThreeMoveSpeed = 200;
int DirectionMoveSpeed = 50;
int MatchSpeed = 70;
Boolean leftflag, rightflag;
int minSpeed = 55;
int factor = 23;
VOID Setup
{
infraredReceiverDecode.begin();
Serial.begin(9600);
}
void loop
{
if(infraredReceiverDecode.buttonState() == 1)
{
switch(infraredReceiverDecode.Read())
{
Case IR_BUTTON_PLUS:
Serial.println ("vooruit");
Forward (); //control de drie motoren
breken;
Case IR_BUTTON_MINUS:
Achterwaarts (); //control de drie motoren
breken;
Case IR_BUTTON_NEXT:
TurnRight (); //control de richting van eBay motors
breken;
Case IR_BUTTON_PREVIOUS:
TurnLeft (); //control de richting van eBay motors
breken;
Case IR_BUTTON_9:
danceOneRound();
danceOneRound();
danceOneRound();
breken;
Case IR_BUTTON_8:
testMoveRound();
breken;
Case IR_BUTTON_7:
excursionWheel1();
breken;
Case IR_BUTTON_6:
RunMotor3Back();
breken;
Case IR_BUTTON_5:
RunMotor2Back();
breken;
Case IR_BUTTON_4:
RunMotor1Back();
breken;
Case IR_BUTTON_3:
RunMotor3Forward();
breken;
Case IR_BUTTON_2:
RunMotor2Forward();
breken;
Case IR_BUTTON_1:
RunMotor1Forward();
breken;
standaard:
Stop();
breken;
}
}
anders
{
Stop();
}
}
VOID danceOneRound () //drive de drie motoren en richting motor zodat de auto-dans
{
Motor1.run(200);
Motor2.run(-200);
Motor3.run(200);
MotorDirection.run(200);
delay(700);
MotorDirection.run(-200);
delay(700);
}
VOID shake()
{
Motor1.run(-250);
Motor2.run(-180);
Motor3.run(0);
}
VOID shake1()
{
Motor1.run(-40);
Motor2.run(-250);
Motor3.run(-40);
}
VOID testMoveRound()
{
Motor1.run(-250);
Motor2.run(-70);
Motor3.run(0);
}
VOID excursionWheel1()
{
Vooruit();
delay(2000);
Motor1.run(-250);
Motor2.run(-250);
Motor3.run(0);
delay(2000);
Stop();
}
void (Forward) //control de drie motoren
{
Motor1.run(ThreeMoveSpeed);
Motor2.run(-ThreeMoveSpeed);
Motor3.run(-ThreeMoveSpeed);
}
void (neerwaarts) //control de drie motoren
{
Motor1.run(-ThreeMoveSpeed);
Motor2.run(ThreeMoveSpeed);
Motor3.run(ThreeMoveSpeed);
}
VOID TurnLeft () //control de richting van eBay motors
{
MotorDirection.run(-DirectionMoveSpeed);
}
VOID TurnRight () //control de richting van eBay motors
{
MotorDirection.run(DirectionMoveSpeed);
}
VOID RunMotor1Forward()
{
Motor1.run(0);
Motor2.run(-ThreeMoveSpeed);
Motor3.run(-ThreeMoveSpeed);
}
VOID RunMotor2Forward()
{
Motor1.run(ThreeMoveSpeed);
Motor2.run(0);
Motor3.run(-ThreeMoveSpeed);
}
VOID RunMotor3Forward()
{
Motor1.run(ThreeMoveSpeed);
Motor2.run(-ThreeMoveSpeed);
Motor3.run(0);
}
VOID RunMotor1Back()
{
Motor1.run(0);
Motor2.run(ThreeMoveSpeed);
Motor3.run(ThreeMoveSpeed);
}
VOID RunMotor2Back()
{
Motor1.run(-ThreeMoveSpeed);
Motor2.run(0);
Motor3.run(MatchSpeed);
}
VOID RunMotor3Back()
{
Motor1.run(-ThreeMoveSpeed);
Motor2.run(ThreeMoveSpeed);
Motor3.run(0);
}
VOID Stop()
{
Motor1.run(0);
Motor2.run(0);
Motor3.run(0);
MotorDirection.run(0);
}
VOID ChangeSpeed(int spd)
{
ThreeMoveSpeed = EPD;
}