Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Program to operate DIY MakeBlock Forklift with Infra red control
#include "MeOrion.h"
#include <SoftwareSerial.h>
MeInfraredReceiver infraredReceiverDecode(PORT_6);
MeDCMotor MotorL(M1);
MeDCMotor MotorR(M2);
MeDCMotor Holder(PORT_1);
MeDCMotor Hand(PORT_2);
int distance=0;
int HolderSpeed = 250;
int HandSpeed = 250;
int moveSpeed = 190;
boolean leftflag,rightflag;
int minSpeed = 55;
int factor = 23;
void setup()
{
infraredReceiverDecode.begin();
}
void loop()
{
uint8_t ReceiverCode;
if(infraredReceiverDecode.available())
{
ReceiverCode = infraredReceiverDecode.read();
switch(ReceiverCode)
{
case IR_BUTTON_A:Holder_up() ; break;
case IR_BUTTON_C:Hand_open() ; break;
case IR_BUTTON_D:Holder_down() ; break;
case IR_BUTTON_E:Hand_close() ; break;
case IR_BUTTON_SETTING: Stop(); break;
case IR_BUTTON_UP: Forward(); break;
case IR_BUTTON_DOWN: Backward(); break;
case IR_BUTTON_LEFT: TurnLeft(); break;
case IR_BUTTON_RIGHT:TurnRight(); break;
case IR_BUTTON_1:ChangeSpeed(factor*1+minSpeed) ; break;
case IR_BUTTON_2:ChangeSpeed(factor*2+minSpeed) ; break;
case IR_BUTTON_3:ChangeSpeed(factor*3+minSpeed) ; break;
case IR_BUTTON_4:ChangeSpeed(factor*4+minSpeed) ; break;
case IR_BUTTON_5:ChangeSpeed(factor*5+minSpeed) ; break;
case IR_BUTTON_6:ChangeSpeed(factor*6+minSpeed) ; break;
case IR_BUTTON_7:ChangeSpeed(factor*7+minSpeed) ; break;
case IR_BUTTON_8:ChangeSpeed(factor*8+minSpeed) ; break;
case IR_BUTTON_9:ChangeSpeed(factor*9+minSpeed) ; break;
default: break;
}
}
}
void Forward()
{
MotorL.run(moveSpeed);
MotorR.run(moveSpeed);
}
void Backward()
{
MotorL.run(-moveSpeed);
MotorR.run(-moveSpeed);
}
void TurnLeft()
{
MotorL.run(-moveSpeed);
MotorR.run(moveSpeed);
}
void TurnRight()
{
MotorL.run(moveSpeed);
MotorR.run(-moveSpeed);
}
void Stop()
{
MotorL.run(0);
MotorR.run(0);
Holder.run(0);
Hand.run(0);
}
void ChangeSpeed(int spd)
{
moveSpeed = spd;
}
void Holder_up()
{
Holder.run(HolderSpeed);
}
void Holder_down()
{
Holder.run(-HolderSpeed);
}
void Hand_close()
{
Hand.run(HandSpeed);
}
void Hand_open()
{
Hand.run(-HandSpeed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.