Created
July 2, 2020 06:37
-
-
Save suadanwar/188723950a3dd1ab9375a2acb39c0f83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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