compiling but not working

hello,
I’m trying to develop a small, led-based, reaction time test.
The code compiles, but nothing happens.
I’m sure that the setup is correct, with leds and buttons etc. each at the right place…
I have three buttons and three leds.
One button to execute each trial; one to delete the last session of the test, if incomplete; the third to delete all the data e restart the whole session group.

Is there anybody who wants to take a look to the code?

here is it…

    int sessionNum = 50;
    int trialNum = 60;
    
  const int switchPin = 2;
  const int resetSessionPin = 3;
  const int resetSessionGroupPin = 4;
    
  const int ledPin = 13;
  const int sessionLedPin = 12;
  const int sessionGroupLedPin = 11;
    
    long startTime;
    long endTime;
    long randomTime;
    int elapsedTime;
    
    int dataArray[60][50];
    
    int switchButtonState; // variabile per leggere lo stato del pulsante di test
    int sessionButtonState; // variabile per controllare lo stato delle sessioni (cancella i dati dell'ultima sessione, se incompleta, cioè se contiene anche un solo zero))
    int sessionGroupButtonState;
    
    void setup()
    {
       
      pinMode(switchPin, INPUT);
      pinMode(resetSessionPin, INPUT);
      pinMode(resetSessionGroupPin, INPUT);
      
      pinMode(ledPin, OUTPUT);
      pinMode(sessionLedPin, OUTPUT);
      pinMode(sessionGroupLedPin, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop()
    { 
      
      switchButtonState = digitalRead(switchPin);
      sessionButtonState = digitalRead(resetSessionPin);
      sessionGroupButtonState = digitalRead(resetSessionGroupPin);
      if (sessionGroupButtonState == HIGH)
      {      

        //check if the session reset button is pressed for 4 secs
        int reset = 0;
        for (int i=1; i<40; i=i+1)
        {
        delay(100);
        if(sessionGroupButtonState == HIGH)
        {
        reset = 1;
        }
        else
        {
        reset = 0;
        }
      }
          if (reset == 1)
          {
            resetSessionGroup();
            startSession(1);
          }
          
        } 
  else {
    // turn LED off:
    digitalWrite(sessionGroupLedPin, LOW); 
  }
  }
      
    void resetSessionGroup()
    {
    startTime=0;
    endTime=0;
    randomTime=0;
    elapsedTime=0;
      for (int i=0; i<sessionNum; i=i+1)
      {
        for (int j=0; j<trialNum; j=j+1)
        {
        dataArray[i][j] = 0;
        }
      }  
    digitalWrite(sessionGroupLedPin, HIGH);
    delay(1000);
    digitalWrite(sessionGroupLedPin, LOW);
  }
    
    void startSession(int i)
    {
     Serial.print("Session number: ");
    Serial.print(i); 
    Serial.print(" starting...");
    // il led di sessione lampeggia 3 volte
    for (int k = 1; k <= 3; k = k + 1) 
    {
      Serial.print(k);
      digitalWrite(sessionLedPin, HIGH);
      delay(300);
      digitalWrite(sessionLedPin, LOW);
      delay(500);
    }
    // parte la sessione, composta di 60 accensioni random del led
    for (int j = 1; j <= 60; j = j + 1) 
    {Serial.print("Trial number: ");
      Serial.print(j);
      Random();
    // valorizzo l'array dei tempi di reazione con il tempo j-mo della sessione i-ma
    dataArray[i][j] = elapsedTime;
    }
    }
    
    void resetLastSession()
    
    {
      
      int k;
    for (int i=0; i<sessionNum; i =i+1)
    {
      for (int j=0; j<trialNum; j =j+1)
      {
        if (dataArray[i][j]==0)
       k = i;
        {
          for (int j=0; j<trialNum; j=j+1)
          {
            dataArray[k][j]=0;
          }
        }
      }
    }  
  
  blinkSessionNumber(k+1);
  
  }
  
    void blinkSessionNumber(int i)
    {
    for (int k = 1; k <= i; k = k + 1) 
    {
      digitalWrite(sessionLedPin, HIGH);
      delay(100);
      digitalWrite(sessionLedPin, LOW);
      delay(300);
      Serial.print("Session number: ");
      Serial.print(k);
      Serial.print(" has been reset.");
    }
    }
    
    void Random()
    {
      randomTime = random(4,10);
      randomTime = randomTime*1000;
      delay(randomTime);
      Start();
    }
        
    void Start()
    {
      digitalWrite(ledPin, HIGH);
        startTime = micros();  
  }
    
    void Stop(){
      endTime = micros();
      elapsedTime = (endTime - startTime)+5000;
      Serial.print("Time microseconds: ");
      Serial.println(elapsedTime);
      digitalWrite(ledPin, LOW);
      
       
    }

thank you! :wink:

You are sure that the setup is correct, but I'm not convinced. Are the buttons connected to Arduino pins and the ground ? Do you use external pull-up resistors ? You could enable the internal pull-up resistors: pinMode(switchPin, INPUT_PULLUP); http://arduino.cc/en/Reference/pinMode

You could add a lot more debug messages to the serial monitor. At least after the Serial.begin(), you could add: Serial.println("Hello"); Also after the test of the button, send a debug message, and also in the 4 second wait loop.

If you want me to take a look at the code, please make the indents consistent and add a few comments.

ok, ok...you are right...too hurry... :roll_eyes:

I've tried some Serial.println("Hello") here and there but nothing happens...

I will follow you suggestion

see you later.

so, now i’m udergoing a slow debugging actvity…

not many errors in my code, which fails when i declare a two-dimensional array (60 rows and 50 columns) full of zeros:

int dataArray[60][50] = {0};

probably this isn’t the correct way to initialize it…

help. :slight_smile:

There isn't enough RAM for such a huge array... You are not programming a computer(!), a microcontroller has very constrained resources.

Wow ! What were you going to do with the array ?

I'd like to give the device to a subject, to make him/her use it for two days...it means about 48 sessions (one per hour), each session made of 60 trials (ten minutes of pshyco-vigilance test ), so I need to store about 50 x 60 unsigned "some-data-type"...

probably i'll try to store data in flash or eeprom memory...I don't know...

I'll keep you informed :)

Look for the header "I2C EEPROM", http://playground.arduino.cc//Main/InterfacingWithHardware#Storage

For example the AT24C64 is 8kbyte, uses I2C, and costs less than a dollar. Those chips have a page of 32 byte, so you have to use a good library. The AT24C256 costs about 3 dollars on Ebay and is 32kbyte or 2 dollars at Sparkfun, https://www.sparkfun.com/products/525 Using a microSD card shield is more convenient. You write everything to a file and take the microSD card out and place it in a computer, https://www.sparkfun.com/products/9802

My vote would be for an SD card.

Erdin: Using a microSD card shield is more convenient. You write everything to a file and take the microSD card out and place it in a computer, https://www.sparkfun.com/products/9802

cool...very cool...

i've reduced the size of the array, and now everything works...i think i'll buy a mcro sd shield...

thank you all, have a good day!!!

rob