Calling Up Sketches from Flash

Hi all, So I'm running Kasper Kamperman's Flash Arduino I/O to communicate to and from my board. Instead of using a single onscreen button press (in Flash) to produce a single event (such as turning an LED on & off), I'd like to use an onscreen button press to initiate a particular sketch that's saved in the Arduino's flash memory.

If for example button_A is pressed, run sketch_A; If button_B is pressed, run sketch_B; and so on.

The serial communication is working fine, I'm just not sure how to call up different sketches. Is this done by setting up a "library"?

Any direction would help.

Thanks!

Well, you’re not able to “call different sketches” from a single board.

I think what you’re looking for is a Switch Statement. Basically, it takes the information, and compares it to a bunch of set values, then executes some code based on that information!

This is most likely what you’ll be using:
Here’s the Switch Case 2 example, from the Arduino program:

 /*
   Switch statement  with serial input
  
  Demonstrates the use of a switch statement.  The switch
  statement allows you to choose from among a set of discrete values
  of a variable.  It's like a series of if statements.
  
  To see this sketch in action, open the Serial monitor and send any character.
  The characters a, b, c, d, and e, will turn on LEDs.  Any other character will turn
  the LEDs off.
  
  The circuit:
  * 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
  
  created 1 Jul 2009
  by Tom Igoe 
  
  http://www.arduino.cc/en/Tutorial/SwitchCase2
  */

 void setup() {
   // initialize serial communication:
   Serial.begin(9600); 
    // initialize the LED pins:
       for (int thisPin = 2; thisPin < 7; thisPin++) {
         pinMode(thisPin, OUTPUT);
       } 
 }

 void loop() {
   // read the sensor:
   if (Serial.available() > 0) {
     int inByte = Serial.read();
     // do something different depending on the character received.  
     // The switch statement expects single number values for each case;
     // in this exmaple, though, you're using single quotes to tell
     // the controller to get the ASCII value for the character.  For 
     // example 'a' = 97, 'b' = 98, and so forth:

     switch (inByte) {
     case 'a':    
       digitalWrite(2, HIGH);
       break;
     case 'b':    
       digitalWrite(3, HIGH);
       break;
     case 'c':    
       digitalWrite(4, HIGH);
       break;
     case 'd':    
       digitalWrite(5, HIGH);
       break;
     case 'e':    
       digitalWrite(6, HIGH);
       break;
     default:
       // turn all the LEDs off:
       for (int thisPin = 2; thisPin < 7; thisPin++) {
         digitalWrite(thisPin, LOW);
       }
     } 
   }
 }

The first one is more along the lines of what you’ll need, but this is just for some more ideas of how the Switch function works:

 /*
   Switch statement
  
  Demonstrates the use of a switch statement.  The switch
  statement allows you to choose from among a set of discrete values
  of a variable.  It's like a series of if statements.
  
  To see this sketch in action, but the board and sensor in a well-lit
  room, open the serial monitor, and and move your hand gradually
  down over the sensor.
  
  The circuit:
  * photoresistor from analog in 0 to +5V
  * 10K resistor from analog in 0 to ground
  
  created 1 Jul 2009
  by Tom Igoe 
  
  http://www.arduino.cc/en/Tutorial/SwitchCase
  */

 // these constants won't change:
 const int sensorMin = 0;      // sensor minimum, discovered through experiment
 const int sensorMax = 600;    // sensor maximum, discovered through experiment

 void setup() {
   // initialize serial communication:
   Serial.begin(9600);  
 }

 void loop() {
   // read the sensor:
   int sensorReading = analogRead(0);
   // map the sensor range to a range of four options:
   int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

   // do something different depending on the 
   // range value:
   switch (range) {
   case 0:    // your hand is on the sensor
     Serial.println("dark");
     break;
   case 1:    // your hand is close to the sensor
     Serial.println("dim");
     break;
   case 2:    // your hand is a few inches from the sensor
     Serial.println("medium");
     break;
   case 3:    // your hand is nowhere near the sensor
     Serial.println("bright");
     break;
   } 

 }