Arduino program to communicate with makeblockbluetooth.py
#include <MeOrion.h> | |
#include <Arduino.h> | |
#include <SoftwareSerial.h> | |
#include <Wire.h> | |
#include "MatrixGraphics.h" | |
MeBluetooth bluetooth(PORT_5); | |
MeDCMotor MotorL(M1); | |
MeDCMotor MotorR(M2); | |
MeDCMotor Holder(PORT_1); | |
MeDCMotor Hand(PORT_2); | |
MeLEDMatrix ledMx(PORT_4); | |
MeInfraredReceiver infraredReceiverDecode(PORT_6); | |
MeUltrasonicSensor ultraSensor(PORT_7); | |
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(); | |
ledMx.setBrightness(6); | |
ledMx.setColorIndex(1); | |
bluetooth.begin(115200); | |
ledMx.drawBitmap(0, 0, sizeof(Bitmap_Logo), Bitmap_Logo); | |
buzzerOn(); | |
delay(1000); | |
buzzerOff(); | |
} | |
void loop() | |
{ | |
int inByte = bluetooth.read(); | |
if(inByte=='f') | |
{ | |
TurnRight(); | |
} | |
if(inByte=='s') | |
{ | |
Stop(); | |
} | |
if(inByte=='l') | |
{ | |
Backward(); | |
} | |
if(inByte=='b') | |
{ | |
TurnLeft(); | |
} | |
if(inByte=='r') | |
{ | |
Forward(); | |
} | |
if(inByte=='a') | |
{ | |
Holder_down(); | |
} | |
if(inByte=='c') | |
{ | |
Holder_up(); | |
} | |
if(inByte=='e') | |
{ | |
Hand_close(); | |
} | |
if(inByte=='d') | |
{ | |
Hand_open(); | |
} | |
if(inByte=='1') | |
{ | |
ChangeSpeed(factor*1+minSpeed); | |
} | |
if(inByte=='2') | |
{ | |
ChangeSpeed(factor*2+minSpeed); | |
} | |
if(inByte=='3') | |
{ | |
ChangeSpeed(factor*3+minSpeed); | |
} | |
if(inByte=='4') | |
{ | |
ChangeSpeed(factor*4+minSpeed); | |
} | |
if(inByte=='5') | |
{ | |
ChangeSpeed(factor*5+minSpeed); | |
} | |
if(inByte=='6') | |
{ | |
ChangeSpeed(factor*6+minSpeed); | |
} | |
if(inByte=='7') | |
{ | |
ChangeSpeed(factor*7+minSpeed); | |
} | |
if(inByte=='8') | |
{ | |
ChangeSpeed(factor*8+minSpeed); | |
} | |
if(inByte=='9') | |
{ | |
ChangeSpeed(factor*9+minSpeed); | |
} | |
} | |
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