KravitzLabDevices / FED3_library

GNU General Public License v3.0
6 stars 17 forks source link

Update the timeout function #33

Closed syhchang closed 2 years ago

syhchang commented 3 years ago

Be able to log pokes during the timeout. Label them left_timeout/right_timeout in the date file. Add an argument for a punishing timeout.

KravitzLab commented 2 years ago

Change Timeout() function to this function in a future library release (this one logs pokes during timeout)

void FED3::Timeout(int seconds) {
  int timeoutStart = millis();
  while ((millis() - timeoutStart) < (seconds*1000)) {
    delay (1);
    int displayUpdated = millis();
    if (millis() - displayUpdated < 1000) {
      display.fillRect (5, 20, 200, 25, WHITE); //erase the data on screen without clearing the entire screen by pasting a white box over it
      display.setCursor(6, 36);
      display.print("Timeout: ");
      display.print(round(seconds - ((millis() - timeoutStart)) / 1000));
      display.refresh();
    }

    if (digitalRead(LEFT_POKE) == LOW) {             //If left poke is triggered
      leftPokeTime = millis();
      LeftCount ++;
      leftInterval = 0.0;
      while (digitalRead (LEFT_POKE) == LOW) {}  //Hang here until poke is clear
      leftInterval = (millis() - leftPokeTime);
      UpdateDisplay();
      Event = "LefinTimeOut";
      logdata();
    }

    if (digitalRead(RIGHT_POKE) == LOW) {            //If right poke is triggered
      rightPokeTime = millis();
      RightCount ++;
      rightInterval = 0.0;
      while (digitalRead (RIGHT_POKE) == LOW) {}  //Hang here until poke is clear
      rightInterval = (millis() - rightPokeTime);
      UpdateDisplay();
      Event = "RightinTimeout";
      logdata();
    }
  }

  display.fillRect (5, 20, 100, 25, WHITE);  //erase the data on screen without clearing the entire screen by pasting a white box over it
  UpdateDisplay();
  Left = false;
  Right = false;
} 
KravitzLab commented 2 years ago

Done in v1.14.1