Trying to find out if ARDUINO uno R3 can do complex c file.

I have this code, but I’m trying to find out if I can create multiple similar action scripts and combined them in one big file. For example, when button A on the controller is pressed. it will trigger the pressing “A button non stop script”, and When-pressed B the ARDUINO uno r3 will get triggered to run “B button non stop” script.

#include "Bot.h"

const int ECHOES = 0;

const command INPUTS = {
// Setup controller
{ NOTHING, 250 },
{ TRIGGERS, 5 }, { NOTHING, 150 },
{ TRIGGERS, 5 }, { NOTHING, 150 },
{ A, 5 }, { NOTHING, 250 },

// Go into game
{ HOME, 5 }, { NOTHING, 250 },
{ A, 5 }, { NOTHING, 250 },

// spam A
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 },
{ A, 5 }, { NOTHING, 5 }
};

const int INPUT_REPEAT_BEGIN = 11;
const int INPUTS_LENGTH = sizeof(INPUTS)/sizeof(command);

How to write IF/Else statement to trigger ARDUINO to load different set of scripts? I’m planning to solder a small button on my ARDUINO uno r3 so when I’m not hitting the button my ARDUINO will run a scripted, but once the button is pressed ARDUINO will load a different set of scripts?
Is this idea feasible, I’m planning to write a c++ code to include two separate script.

Thank you in advance!

The nice thing about the Arduino and the IDE is you can try all the various things you are posting about and see if they work. No need to ask if they work.

Paul

I’m new to coding, if possible please tell me some coding to enable this feature?

This has nothing to do with uploads.

You write code to perform all the functions you need, then use a button (or whatever) to let the program know which bits of code to run.
That’s a fundamental element of programming.

The rest is up to you, and help from us if we can.

If all your code won’t fit, then you may need a bigger processor/flash/RAM.

Please kindly give me some example script or formatting. For example, if no button is pressed run “xxxx” and if the button is pressed run “YYY”. I just got my ARDUINO and I’m eager to test this out....

What feature ?
I don’t get what you’re after...

Is the listing you posted the output? or...
We need a lot more info, and to see the code your using.

Please keep questions in the forum, you’ll get more responses.

So, you need to write code that does XXX and YYY, possibly in separate functions, then in loop, test the button… if it’s pressed call one, of its not, call the other.

It gets more complex quickly, but if you do this it will make more sense and give you more questions.

The above code is for press button A, I want to utilize a physical small button soldiered on my ARDUINO pro micro to allow me to switch script to that for example pressing button B without using a computer to flash new script to it..
Thank you for replying!

Because the current running software is stored in FLASH. memory, there’s no ‘on-board’ way to rewrite (or upload) a new program from a storage medium.
You’ll need some external programmer, typically running AVRdude, that can transfer the new hex binary from your repository to the UNO’s FLASH.
This would most likely be via the ISP pins, but could use the serial bootloader if necessary.

Perhaps you can elaborate more on ‘what’ the programs are doing... maybe all the functionality can be contained... or you could bump to a MEGA2560 for more FLASH.

At the moment, your requirements are too vague, and I suspect outside your current skill level.
We all started somewhere,

@Sdokdyg5656, do not cross-post. Threads merged.

I can't find the "Bot.h" library you are using so I have no idea what you are doing with the the table of values you defined.

You can probably define other tables. You can probably switch between tables with a button. Without either the location of the "Bot" library or a working example sketch it will be very hard to help.

Hi,sorry for late reply, the link below will take you to the bot file

The INPUTS list is processed in src/Joystick.c in the case labeled "case PROCESS:". To allow for multiple scripts you will need to use variables in place of the global constants:

extern const command INPUTS[];
extern const int INPUTS_LENGTH;
extern const int INPUT_REPEAT_BEGIN;
extern const int ECHOES;

You can use global variables instead:

extern command *INPUTS;
extern int INPUTS_LENGTH;
extern int INPUT_REPEAT_BEGIN;
extern int ECHOES;

At the top of "case PROCESS:" you would check your buttons to see if the script should change. If the script changes, for example, to "Script1":

INPUTS = Script1_INPUTS;
INPUT_LENGTH = Script1_INPUT_LENGTH;
INPUT_REPEAT_BEGIN = Script1_INPUT_REPEAT_BEGIN;
ECHOES = Script1_ECHOES;
bufindex = 0; // Start at the top of the script!

If you only have a few scripts, you can most easily have one button per script:

// Prepare the next report for the host.
void GetNextReport(USB_JoystickReport_Input_t* const ReportData)
{
  .
  .
  .
  // States and moves management
  switch (state)
  {
      .
      .
      .
    case PROCESS:
      if (digitalRead(Script1ButtonPin) == LOW)
      {
        INPUTS = Script1_INPUTS;
        INPUT_LENGTH = Script1_INPUT_LENGTH;
        INPUT_REPEAT_BEGIN = Script1_INPUT_REPEAT_BEGIN;
        ECHOES = Script1_ECHOES;
        bufindex = 0; // Start at the top of the script!
      }

      if (digitalRead(Script2ButtonPin) == LOW)
      {
        INPUTS = Script2_INPUTS;
        INPUT_LENGTH = Script2_INPUT_LENGTH;
        INPUT_REPEAT_BEGIN = Script2_INPUT_REPEAT_BEGIN;
        ECHOES = Script2_ECHOES;
        bufindex = 0; // Start at the top of the script!
      }

      if (digitalRead(Script3ButtonPin) == LOW)
      {
        INPUTS = Script3_INPUTS;
        INPUT_LENGTH = Script3_INPUT_LENGTH;
        INPUT_REPEAT_BEGIN = Script3_INPUT_REPEAT_BEGIN;
        ECHOES = Script3_ECHOES;
        bufindex = 0; // Start at the top of the script!
      }
      .
      .
      .
  }
}

Thank you so much for the detailed answer and dedication on helping newbie like me! It’s people like you who made the community vivid and helpful!