Is it , Even Possible ,to alter code , after uploading ?

Hey Guys I have an arduino Uno , and leonardo what i basically want to do , is connect a PS3 to the arduino ! the code (on startup) should give me options like ! :-

int game_select(){
Serial.println("Select The Game You Want to Play !");  
Serial.println("1 -> Need For Speed : Most Wanted   ");
Serial.println("2 -> Need For Speed : Hot Pursuit 2 ");
Serial.println("3 -> Call Of Duty : Modern Warfare 3    ");
Serial.println("4 -> UberStrike  ");
Serial.println("5 -> Clash Of Clans    ");
Serial.println("6 -> CUSTOM !!! REM NEW PROGRAM BUILD !    ");
return 0;
  }//this return 0  is under progress , plz understand that i will shortly do the switch code too !

when i select Custom Rem new program build , i should be able to define , what each key on PS3 does , to computer ! eg : if in all games i have left analog stick for mouse look , in custom , i should be able to use right analog stick for that purpose !

and not only that , but also save the custom , naming it , and then shifting the list by one , and adding that custom code to the arduino codes , for further uses !

it will really be handy !

also i need a very similar code for another project ! where i use Ps3 to control 3 devices !

No, you can't alter the code once it is loaded. You could write code that is set up so that it can take that information, save it somewhere like EEPROM or an SD card, and allow yourself to create custom setups for your controller. But that would all have to be built into the code from the start.

Another way is to read configuration switches at boot time.

can u guys , please elaborate ur advice ?

I'll help you start.

First make a list of all the buttons on the controller (on paper). Next make a list of all the possible outputs, all the things that any one button can do.

Now encode that. So maybe each possible output gets a number. 1 means press the space bar. 2 means press shift. 3 means A, 4 means S, 5 means D, 6 means W. Or whatever you need so that these encodings are linked to actions and not the buttons themselves.

Now you'll need some sort of data structure to hold that information so that when button is pressed it looks up what it is supposed to do. Maybe you create an order for all the different buttons and put the number codes for each button in the right order so the first number read out tells you what the up button does and the next number tells you what the down button does and the next number for left etc etc.

Next, you need a way to store that information so that it isn't hard coded. The program looks to an EEPROM location or an SD card file and finds all of the configuration data and fills that data structure.

Now the program starts to look like this: When a button on the controller is pressed, we look in the data structure and find the code number that goes with that button. Then we lookup the action that number represents and run the code that goes with that action. So the button press and the action taken are separated by this lookup of which action to perform.

Finally, write some code that allows you to build these structures and store them in the EEPROM or SD for later retrieval.

nice ! really helpful ! now , as far as i think , eeprom should be enough ? what do u think ? i am thinking of that there are total of 14 buttons , 2 joysticks , so i will create a partition like : eeprom has 512 points for data storage , so .... max custom programs i will save will be 8 , so 512 / 8 = 64 bytes ! now 1st byte will contain what will button 1 on PS3 will do , and byte 2 will contain what button 2 will do , an soo onn ! this is the basic idea i have !

do u have a better idea , for eeprom storage only ! i wont be able to use an SD card !

If we were talking about the old Nintendo controller from the 80's...

With these new video games I don't really have any idea how many buttons there are or what the controllers look like or what sorts of things one might expect them to do. Been a while since I played any video games. I would suggest a lot of work on paper first to try to come up with encodings before you start writing any code. Once you have it laid out on paper it should become apparent how many bytes it should take to hold the data.

It all depends on how many things you are encoding. For example, if there are less than 16 possible actions, then maybe two codes could fit in one byte. All sorts of tricks to play, but there's no way to plan that until you have it all out on paper so you can organize it.

dude , i am talking about DualShock 3 SixAxis Controller

Actually there is, if you feel up to creating a pseudo code program and writing Arduino code to interpret it. Not something for the faint-of-heart, but is doable.

Paul

it has the following Inputs :-

Motion sensing (3 Axes, 6 DoF) 2 × Analog sticks (10-bit precision) 2 × Analog triggers (L2, R2) 6 × Pressure-sensitive buttons (Triangle, Circle, Cross, Square, L1, R1) Pressure-sensitive D-Pad 5 × Digital buttons ("PS", L3, R3, Start, Select) Connectivity USB, Bluetooth (PlayStation 3 and PSP Go)

Paul , i could not get u , can u plz elaborate ?

Serial.println("Select The Game You Want to Play !");

Before imminent heartache and hair-loss, find out a little about the F() macro.

harslu8: dude , i am talking about DualShock 3 SixAxis Controller

I have absolutely no idea what that is. I put video games down long long ago and decided to dedicate my life to things of real consequence.

But the idea is the same. It has some buttons. Those buttons trigger some output. You want to map the buttons to the outputs.

Maybe the simplest thing would be to work out how the code would work for an old atari stick, 4 directions and a button. That will let you get the code structure in place while everything else is relatively simple. Then, once you have working code add more buttons to it and make it work with the new controller.

harslu8: Paul , i could not get u , can u plz elaborate ?

I had written a long dissertation on how to do what you want using an array of fixed length strings. Each string would be a line of pseudo code that would be interpreted by the Arduino program. Each line would have a numeric id that would control which part of the Arduino interpreter to be run. when that last line in the array had been interpreted, go back to the first line and start over.

As I got further into it, I realized you have not given enough information about the capabilities of the game controller. Can you use it to enter the name you want to give the program? Does it have capability to signal you want to add or delete a button? Can you use it to enter what you want a button to do when pressed?

You need to go through the exercise that Delta_G suggested and add to that list every other action you would like to program to do, ie. save program, retrieve program, add a button with it's action, etc.

Then we can see if what you are suggesting is possible using a game controller.

Paul

hey guys , in the same project i have problems , it does not allow me to take the option i want to !

plz run it into ur arduino , and help me debug it ! all suggestions are welcomed !

void nefmw(){
  Serial.println("NFS MW");
  };
void nfshp(){
  Serial.println("NFS HP");
  };
void codmw3(){
  Serial.println("COD MW3");
  };
void uberstrike(){
  Serial.println("UBERSTRIKE");
  };
void coc(){
  Serial.println("CLASH OF CLANS");
  };
void custom(){
  Serial.println("CUSTOM");
  };

void welcome(){
Serial.println(" 11    11  11111  11     11111  111111  111  111  11111  ");
Serial.println(" 11    11  11     11     11     11  11  111  111  11     ");
Serial.println(" 11    11  11     11     11     11  11  11 11 11  11     ");  
Serial.println(" 11    11  11111  11     11     11  11  11    11  11111  ");   
Serial.println(" 11 11 11  11     11     11     11  11  11    11  11     ");   
Serial.println(" 111  111  11     11     11     11  11  11    11  11     ");   
Serial.println(" 111  111  11111  11111  11111  111111  11    11  11111  ");
Serial.println();   
   }

int ch;
int game_select(){
    int x=0;
Serial.println("Select The Game You Want to Play ! \n");  
Serial.println("1 -> Need For Speed : Most Wanted");
Serial.println("2 -> Need For Speed : Hot Pursuit 2");
Serial.println("3 -> Call Of Duty : Modern Warfare 3");
Serial.println("4 -> UberStrike");
Serial.println("5 -> Clash Of Clans");
Serial.println("6 -> CUSTOM !!! REM NEW PROGRAM BUILD ! \n");
while(x==0){
if(Serial.available()>0);{x=Serial.read();x=x-'0'; }
return x ;
  }
}
void setup() {
  // put your setup code here, to run once:
Serial.begin(57600);
delay(2000);
Serial.println("Initializing Arduino , Please Wait ! \n");delay(500);
welcome();
delay(2000);
Serial.println("Code Initialized , And Running \n");delay(1000);
ch=game_select();
switch(ch){
  case 1:nefmw();break;
  case 2:nfshp();break;
  case 3:codmw3();break;
  case 4:uberstrike();break;
  case 5:coc();break;
  case 6:custom();break;
  default:break;//end(0);
  }
  
}

void loop() {
  // put your main code here, to run repeatedly:

}

when after the list of games i enter a number , nothing happens !

Guys , i looked up some tutorials , and found that i need to subtract character 0 from x i tried it , but no help ! if(Serial.available()>0);{x=Serial.read();x=x-'0'; }

Serial.println(" 11    11  11111  11     11111  111111  111  111  11111  ");
Serial.println(" 11    11  11     11     11     11  11  111  111  11     ");
Serial.println(" 11    11  11     11     11     11  11  11 11 11  11     ");  
Serial.println(" 11    11  11111  11     11     11  11  11    11  11111  ");   
Serial.println(" 11 11 11  11     11     11     11  11  11    11  11     ");   
Serial.println(" 111  111  11     11     11     11  11  11    11  11     ");   
Serial.println(" 111  111  11111  11111  11111  111111  11    11  11111  ");

You're going to get into memory trouble real soon. Time to learn about the F macro to hold those strings in flash memory. You only have 2KB of RAM. Don't waste it on stuff like this if you don't have to.

KK SO SHOULD I USE

Serial.println(F("1111 11111 (i think u can get me )"));

harslu8: KK SO SHOULD I USE

Serial.println(F("1111 11111 (i think u can get me )"));

Definitely!

OK , BUT WHAT ABOUT THE BUG IN MY CODE ? I CANT ACCEPT NUMBERS FROM THE SERIAL MONITOR !