Remote controll

I am trying to wirelessly control a robot. I’m using a uno for the controller and a mega for the robot.

I’m trying to create “packets” of information to from the uno to the mega, is the very last section of code an approprate way to do this?

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX

//Create variables for each button on the Joystick Shield to assign the pin numbers

char button0=8, button1=9, button2=10, button3=11;
char sel = 12;
int packet = {0,0,0,0,0,0,0};
int i = 0;

void setup()
{
pinMode(sel, INPUT); //Set the Joystick 'Select’button as an input
digitalWrite(sel, HIGH); //Enable the pull-up resistor on the select button

pinMode(button0, INPUT); //Set the Joystick button 0 as an input
digitalWrite(button0, HIGH); //Enable the pull-up resistor on button 0

pinMode(button1, INPUT); //Set the Joystick button 1 as an input
digitalWrite(button1, HIGH); //Enable the pull-up resistor on button 1

pinMode(button2, INPUT); //Set the Joystick button 2 as an input
digitalWrite(button2, HIGH); //Enable the pull-up resistor on button 2

pinMode(button3, INPUT); //Set the Joystick button 3 as an input
digitalWrite(button3, HIGH); //Enable the pull-up resistor on button 3

// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.println(“Shake and Bake! I’m an Uno”);

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println(“Hello, world?”);
}

void loop() // run over and over
{

//AnalogSignals - Joystick
packet[0] = analogRead(0); //Read the position of the joysticks X axis and print it on the serial port.
packet[0] = map(packet[0],0,1023,0,255);
packet[1] = analogRead(1); //Read the position of the joysticks Y axis and print it on the serial port.
packet[1] = map(packet[1],0,1023,0,255);

//DigitalSignals - Buttons
packet[2] = digitalRead(sel); //Read the value of the select button and print it on the serial port.
packet[3] = digitalRead(button0); //Read the value of the button 0 and print it on the serial port.
packet[4] = digitalRead(button1); //Read the value of the button 1 and print it on the serial port.
packet[5] = digitalRead(button2); //Read the value of the button 2 and print it on the serial port.
packet[6] = digitalRead(button3); //Read the value of the button 3 and print it on the serial port.

//Wait for 100 ms, then go back to the beginning of ‘loop’ and repeat.
delay(100);

//if (Serial.available()) {

for (i = 0 ; i < 7 ; i++){
mySerial.write(packet*);*
_ Serial.print(packet*);_
_
Serial.print(" ");_
_
delay(100);*_

}
Serial.println(" ");
}

packet[0] = analogRead(0);  //Read the position of the joysticks X axis and print it on the serial port.
  packet[0] = map(packet[0],0,1023,0,255);
  packet[1] = analogRead(1);  //Read the position of the joysticks Y axis and print it on the serial port.
  packet[1] = map(packet[1],0,1023,0,255);

map() is pretty expensive way to divide by 4.

Does your code really look like this:

  for (i = 0 ; i < 7 ; i++){
    mySerial.write(packet);
    Serial.print(packet);
    Serial.print(" ");
    delay(100);
   
 }
 Serial.println(" ");
}

I seriously doubt it. Now, go read the posts at the top of the forum that you were supposed to read BEFORE posting the first time.

  for (i = 0 ; i < 7 ; i++){
    mySerial.write(packet);
    Serial.print(packet);
    Serial.print(" ");
    delay(100);
   
 }

Why are you writing/printing the same thing 7 times?

What is at the other end of mySerial? What will it do with “hello world”?

…R