store sensor values into an array

meowth08:

Did you get your initial question of saving the switch number and a value saved to an array sorted out ?

No sir. I am having difficulty transforming the pseudo code in C.

Something (untested) to get you started.

byte dataArray[200];          //room for 200 entries.  100 switch numbers, 100 data entries
int leftsw = 11;
int rightsw = 10;
int sensorPin = A0;
int sensorData;
int arrayIndex = 0;

void setup() 
{
  pinMode(leftsw,INPUT);
  pinMode(rightsw, INPUT);
  pinMode(sensorPin, INPUT);
}

void loop() 
{
  if (digitalRead(leftsw) == HIGH)        //left switch pressed
  {
    sensorData = analogRead(sensorPin);   //read sensor
    //constrain and mapping here if required
    dataArray[arrayIndex] = 0;            //save zero to array to indicate left switch pressed
    arrayIndex++;                         //move index to next array position
    dataArray[arrayIndex] = sensorData;   //save sensor data to array
    arrayIndex++;                         //move index to next array position 
  }

  if (digitalRead(rightsw) == HIGH)       //right switch pressed
  {
    sensorData = analogRead(sensorPin);   //read sensor
    //constrain and mapping here if required
    dataArray[arrayIndex] = 1;            //save 1 to array to indicate right switch pressed
    arrayIndex++;                         //move index to next array position
    dataArray[arrayIndex] = sensorData;   //save sensor data to array
    arrayIndex++;                         //move index to next array position
  }

  //***************************************************************
  //neater way to do the same thing - DO NOT LEAVE BOTH IN LOOP() !
  //***************************************************************
  if (digitalRead(leftsw) == HIGH)        //left switch pressed
  {
    saveData(0);
  }

  if (digitalRead(leftsw) == HIGH)        //left switch pressed
  {
    saveData(1);
  }
}

//***********************************************************************
void saveData(int swNum)              //function to save switch number and data
{
  sensorData = analogRead(sensorPin);   //read sensor
  //constrain and mapping here if required
  dataArray[arrayIndex] = swNum;            //save switch number
  arrayIndex++;                         //move index to next array position
  dataArray[arrayIndex] = sensorData;   //save sensor data to array
  arrayIndex++;                         //move index to next array position 
}