BT connection improved. Requstes to enable BT. 5 speed implementation.
UI improvements
This commit is contained in:
@ -14,61 +14,80 @@ const int offsetA = 1;
|
||||
const int offsetB = -1;
|
||||
|
||||
SoftwareSerial BTSerial(3, 2); // RX | TX
|
||||
String reader;
|
||||
Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);
|
||||
Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY);
|
||||
Motor motorA = Motor(AIN1, AIN2, PWMA, offsetA, STBY);
|
||||
Motor motorB = Motor(BIN1, BIN2, PWMB, offsetB, STBY);
|
||||
|
||||
void setup()
|
||||
{
|
||||
//Serial.begin(9600);
|
||||
//Serial.println("Ready:");
|
||||
BTSerial.begin(9600); // HC-05 default speed in AT command more
|
||||
brake(motor1, motor2);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
char m1 = '9';
|
||||
char m2 = '9';
|
||||
char motorADirection = 'f';
|
||||
char motorBDirection = 'f';
|
||||
char motorASpeed = '0';
|
||||
char motorBSpeed = '0';
|
||||
int motorAVelocity = 0;
|
||||
int motorBVelocity = 0;
|
||||
//Serial.println("There is "+String(BTSerial.available())+" available");
|
||||
if (BTSerial.available()==2) {
|
||||
m1 = BTSerial.read();
|
||||
m2 = BTSerial.read();
|
||||
//Serial.println("Receved: "+String(m1)+";"+String(m2));
|
||||
switch (m1) {
|
||||
if (BTSerial.available() == 4) {
|
||||
motorADirection = BTSerial.read();
|
||||
motorASpeed = BTSerial.read();
|
||||
motorBDirection = BTSerial.read();
|
||||
motorBSpeed = BTSerial.read();
|
||||
//Serial.println("Receved: "+String(motorADirection)+String(motorASpeed)+String(motorBDirection)+String(motorBSpeed));
|
||||
switch (motorASpeed) {
|
||||
case '0':
|
||||
motor1.drive(-255);
|
||||
motorAVelocity = 0;
|
||||
break;
|
||||
case '1':
|
||||
motor1.drive(-170);
|
||||
motorAVelocity = 100;
|
||||
break;
|
||||
case '2':
|
||||
motor1.drive(0);
|
||||
motorAVelocity = 140;
|
||||
break;
|
||||
case '3':
|
||||
motor1.drive(170);
|
||||
motorAVelocity = 180;
|
||||
break;
|
||||
case '4':
|
||||
motor1.drive(255);
|
||||
motorAVelocity = 200;
|
||||
break;
|
||||
case '5':
|
||||
motorAVelocity = 225;
|
||||
break;
|
||||
}
|
||||
switch (m2) {
|
||||
switch (motorBSpeed) {
|
||||
case '0':
|
||||
motor2.drive(-255);
|
||||
motorBVelocity = 0;
|
||||
break;
|
||||
case '1':
|
||||
motor2.drive(-170);
|
||||
motorBVelocity = 100;
|
||||
break;
|
||||
case '2':
|
||||
motor2.drive(0);
|
||||
motorBVelocity = 140;
|
||||
break;
|
||||
case '3':
|
||||
motor2.drive(170);
|
||||
motorBVelocity = 180;
|
||||
break;
|
||||
case '4':
|
||||
motor2.drive(255);
|
||||
motorBVelocity = 200;
|
||||
break;
|
||||
}
|
||||
case '5':
|
||||
motorBVelocity = 225;
|
||||
break;
|
||||
}
|
||||
if (motorADirection == 'b') {
|
||||
motorAVelocity = 0 - motorAVelocity;
|
||||
}
|
||||
if (motorBDirection == 'b') {
|
||||
motorBVelocity = 0 - motorBVelocity;
|
||||
}
|
||||
//Serial.println("A: "+String(motorAVelocity)+"; B: "+String(motorBVelocity));
|
||||
motorA.drive(motorAVelocity);
|
||||
motorB.drive(motorBVelocity);
|
||||
}
|
||||
|
||||
}
|
||||
|
34
Arduino/motor_test/motor_test.ino
Normal file
34
Arduino/motor_test/motor_test.ino
Normal file
@ -0,0 +1,34 @@
|
||||
#include <SparkFun_TB6612.h>
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define AIN1 4
|
||||
#define BIN1 8
|
||||
#define AIN2 5
|
||||
#define BIN2 7
|
||||
#define PWMA 11
|
||||
#define PWMB 10
|
||||
#define STBY 6
|
||||
|
||||
const int offsetA = 1;
|
||||
const int offsetB = -1;
|
||||
|
||||
Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);
|
||||
Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Ready:");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int v = 0;
|
||||
while(v<=255) {
|
||||
motor2.drive(v);
|
||||
Serial.println("Speed: "+String(v));
|
||||
delay(100);
|
||||
v = v+1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user