Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include "CytronMotorDriver.h"
CytronMD motorLeft(PWM_PWM, 11, 10);
CytronMD motorRight(PWM_PWM, 9, 3);
#define BT_TX 6
#define BT_RX 7
#include "SoftwareSerial.h"
SoftwareSerial BTSerial(BT_TX, BT_RX); // Maker UNO RX, TX
#define BUTTON 2
#define NOTE_G4 392
#define NOTE_C5 523
#define NOTE_G5 784
#define NOTE_C6 1047
int btConnect[] = {NOTE_G5, NOTE_C6};
int btConnectNoteDurations[] = {12, 8};
#define playBtConnectMelody() playMelody(btConnect, btConnectNoteDurations, 2)
boolean BTConnect = false;
char inChar;
void robotStop() {
motorLeft.setSpeed(0);
motorRight.setSpeed(0);
}
void robotMove(int speedLeft, int speedRight) {
motorLeft.setSpeed(speedLeft);
motorRight.setSpeed(speedRight);
}
void setup()
{
pinMode(BUTTON, INPUT_PULLUP);
Serial.begin(9600);
BTSerial.begin(9600);
delay(1000);
}
void loop()
{
inChar = 'S';
if (BTSerial.available()) {
inChar = BTSerial.read();
Serial.println(inChar);
}
if (inChar == 'F') {
robotMove(200, 200); //forward
delay(1000);
}
else if (inChar == 'B') {
robotMove(-200, -200); //reverse
delay(1000);
}
else if (inChar == 'L') {
robotMove(-200, 200); //left
delay(1000);
}
else if (inChar == 'R') {
robotMove(200, -200); //right
delay(1000);
}
else if (inChar == 'S') {
robotStop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment