remote control and sensor control in same project

Hi everyone,

I have URC10 controller(https://www.cytron.io/p-urc10) that is connected to PS2 controller and LCD display shields. I finished 2 separate codes for remote controlled and also sensor controlled robot. Now I want to put them in the same project.

So in ideal it should work like this: When starting the robot, LCD gives two options: Remote mode and Sensor mode. After choosing any of the modes, either remote controlled mode or sensor controlled mode starts and you can any time go back to the main menu to choose another option.

Here’s how I’ve approached it so far:
I wrote LCD display code in the .ino file created separate tabs for remote control and sensor control. In each of them, instead of void setup() and void loop() I changed to void setupRemote(), void setupSensor() and void loopRemote(), void loopSensor().

I havent gotten it to work yet, but am I on the right track? Could it work that way?

Edit:
LCD Menu code(removed all the functions and included only setup() and loop()):

String menuItems[] = {"Remote mode", "Sensor mode"};

// Navigation button variables
int readKey;
int savedDistance = 0;

// Menu control variables
int menuPage = 0;
int maxMenuPages = round(((sizeof(menuItems) / sizeof(String)) / 2) + .5);
int cursorPosition = 0;

byte menuCursor[8] = {
  B01000, //  *
  B00100, //   *
  B00010, //    *
  B00001, //     *
  B00010, //    *
  B00100, //   *
  B01000, //  *
  B00000  //
};

#include <Wire.h>
#include <LiquidCrystal.h>

// Setting the LCD shields pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {

  // Initializes serial communication
  Serial.begin(9600);

  // Initializes and clears the LCD screen
  lcd.begin(16, 2);
  lcd.clear();
  setupRemote();
  // Creates the byte for the 3 custom characters
  lcd.createChar(0, menuCursor);
}

void loop() {
  mainMenuDraw();
  drawCursor();
  operateMainMenu();
}

Remote control code(removed all the functions and included only setup() and loop()):

#include <SoftwareSerial.h>
#include <Cytron_PS2Shield.h> //PS2 shield library
Cytron_PS2Shield ps2(2, 3); // SoftwareSerial: Rx and Tx pin
#include<math.h>

int dig1=7;  //pin signal for motor left
int dig2=4;  //pin signal for motor right
int an1=6;   //pin pwm for motor left
int an2=5;   //pin pwm for motor right 


int ly=0;
int lx=0;
int xaxis=0;
int yaxis=0;
int acc=0;


void setup()
{
  ps2.begin(9600); // This baudrate must same with the jumper setting at PS2 shield
  ps2.reset(1);             //call to reset Shield-PS2
  delay(100);
  ps2.reset(0);
  pinMode(dig1,OUTPUT);      //initialize for all the input and output
  pinMode(dig2,OUTPUT);
  pinMode(an1,INPUT);
  pinMode(an2,INPUT);
  Serial.begin(9600);
  analogWrite(an1,0);  //Based on the datasheet, the MDDS10 analog pin should get 0 input upon start 
  analogWrite(an2,0);  //thus we need to send 0 value at the beginning
  delay(1000);                        
  
}

void loop()
{
    //joystick value
    ly=ps2.readButton(PS2_JOYSTICK_LEFT_Y_AXIS);
    lx=ps2.readButton(PS2_JOYSTICK_LEFT_X_AXIS);
    acc=(ps2.readButton(PS2_LEFT_2) == 0);
   
     
     if(acc==HIGH)
     {
     Normal();}         //function call for normal speed
     else{
     Acceleration();}   //function call for higher speed
     Movement();
   
    
}

So basically how can I put include these into one project so they would work together.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Thank you Tom! Now I included the lcd and remote control codes in the first post.

inzzza8:
Thank you Tom! Now I included the lcd and remote control codes in the first post.

So, you made Tom look like an idiot for commenting on missing code, when it now appears to be there.

Why would anyone risk responding to your post now? I'd be afraid of being made to look like an idiot.

You do NOT have two codes running on the Arduino. Post the ONE code that you are having problems with IN A NEW REPLY!