Topic: Bleutooth servo car
Hello everybody,
I have a little problem with my project at school,
the motor and servo arent operating as I hoped.
when i slide the slider all the way to the left it keeps on going to the left,
when i slide it to the right it goes to the left for 0.5sec en then slow to the right
the 2 motors arent responding at all...
i'm new to the arduino programming so that's why i am asking you guys to help me
*sorry for bad english im from holland (Netherlands)
Here is the code:
/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 2.2.5 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 3.7.1 or later version;
- for iOS 1.0.7 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__HARDSERIAL
#include <Servo.h>
Servo myservo;
Servo myservo_1;
#include <SoftwareSerial.h>
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial1
#define REMOTEXY_SERIAL_SPEED 9600
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 5,0,58,0,6,7,0,2,0,12
,6,22,11,2,226,152,188,0,79,70
,70,0,1,1,54,16,12,12,2,226
,153,171,0,2,0,12,23,22,11,2
,226,150,178,0,226,150,188,0,4,176
,1,46,58,9,2,4,32,80,2,8
,57,2 };
// this structure defines all the variables of your control interface
struct {
// input variable
uint8_t R; // =1 if switch ON and =0 if OFF
uint8_t button_5; // =1 if button pressed, else =0
uint8_t switch_1; // =1 if switch ON and =0 if OFF
int8_t slider_1; // =-100..100 slider position
int8_t slider_2; // =-100..100 slider position
uint8_t PIN_DIR_1A;
uint8_t PIN_DIR_1B;
uint8_t PIN_DIR_2A;
uint8_t PIN_DIR_2B;
uint8_t PIN_SPD_1;
uint8_t PIN_SPD_2;
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_R 13
#define PIN_BUTTON_5 10
#define PIN_SWITCH_1 A0
#define PIN_DIR_1A 7
#define PIN_DIR_1B 12
#define PIN_DIR_2A 11
#define PIN_DIR_2B 6
#define PIN_SPD_1 5
#define PIN_SPD_2 13
void setup()
{
RemoteXY_Init ();
myservo.attach(A1);
pinMode (PIN_R, OUTPUT);
pinMode (PIN_BUTTON_5, OUTPUT);
pinMode (PIN_SWITCH_1, OUTPUT);
RemoteXY.slider_1 = 0;
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_R, (RemoteXY.R==0)?LOW:HIGH);
digitalWrite(PIN_BUTTON_5, (RemoteXY.button_5==0)?LOW:HIGH);
digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
int pos = RemoteXY.slider_2;
if (pos>0) { // up
digitalWrite(7, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(6, LOW);
analogWrite(5, 255/100*RemoteXY.slider_2);
analogWrite(13, 255/100*RemoteXY.slider_2);
}
else if (pos<0) { // down
digitalWrite(PIN_DIR_1A, LOW);
digitalWrite(PIN_DIR_1B, HIGH);
digitalWrite(PIN_DIR_2A, LOW);
digitalWrite(PIN_DIR_2B, HIGH);
analogWrite(PIN_SPD_1, 255/100*pos);
analogWrite(PIN_SPD_2, (0-pos) * 2.55);
}
else { // stop
digitalWrite(PIN_DIR_1A, LOW);
digitalWrite(PIN_DIR_1B, LOW);
digitalWrite(PIN_DIR_2A, LOW);
digitalWrite(PIN_DIR_2B, LOW);
analogWrite(PIN_SPD_1, 0);
analogWrite(PIN_SPD_2, 0);
}
{
int pos = RemoteXY.slider_1;
if (pos>0) { // Rechts
analogWrite(A1, RemoteXY.slider_1 * 2.55);
myservo.writeMicroseconds(RemoteXY.slider_1 * 20 + 500);
}
else if (pos<-0) { // Links
analogWrite(A1, RemoteXY.slider_1 * 2.55);
myservo.writeMicroseconds(2500 - RemoteXY.slider_1 * 20);
}
// TODO you loop code
// use the RemoteXY structure for data transfer
}
}
With kind regards,
Kellen