@@ -319,7 +319,30 @@ bool FED3::ClearJam() {
319319
320320bool FED3::RotateDisk (int steps) {
321321 digitalWrite (MOTOR_ENABLE, HIGH); // Enable motor driver
322- for (int i = 0 ; i < (steps>0 ?steps:-steps); i++) {
322+ for (int i = 0 ; i < (steps>0 ?steps:-steps); i++) {
323+
324+ if (digitalRead (LEFT_POKE) == LOW) { // If left poke is triggered
325+ leftPokeTime = millis ();
326+ LeftCount ++;
327+ leftInterval = 0.0 ;
328+ while (digitalRead (LEFT_POKE) == LOW) {} // Hang here until poke is clear
329+ leftInterval = (millis () - leftPokeTime);
330+ UpdateDisplay ();
331+ Event = " LeftDuringDispense" ;
332+ logdata ();
333+ }
334+
335+ if (digitalRead (RIGHT_POKE) == LOW) { // If right poke is triggered
336+ rightPokeTime = millis ();
337+ RightCount ++;
338+ rightInterval = 0.0 ;
339+ while (digitalRead (RIGHT_POKE) == LOW) {} // Hang here until poke is clear
340+ rightInterval = (millis () - rightPokeTime);
341+ UpdateDisplay ();
342+ Event = " RightDuringDispense" ;
343+ logdata ();
344+ }
345+
323346 if (steps > 0 )
324347 stepper.step (1 );
325348 else
@@ -359,18 +382,26 @@ bool FED3::dispenseTimer_ms(int ms) {
359382
360383// Timeout function
361384void FED3::Timeout (int seconds) {
362- DateTime now = rtc.now ();
363- unixtime = now.unixtime ();
364- unsigned long TimeoutStart = now.unixtime ();
365- while (unixtime - TimeoutStart < seconds) {
366- // Log pokes while pellet is present
385+ int timeoutStart = millis ();
386+ while ((millis () - timeoutStart) < (seconds*1000 )) {
387+ delay (1 );
388+ int displayUpdated = millis ();
389+ if (millis () - displayUpdated < 1000 ) {
390+ display.fillRect (5 , 20 , 200 , 25 , WHITE); // erase the data on screen without clearing the entire screen by pasting a white box over it
391+ display.setCursor (6 , 36 );
392+ display.print (" Timeout: " );
393+ display.print (round (seconds - ((millis () - timeoutStart)) / 1000 ));
394+ display.refresh ();
395+ }
396+
367397 if (digitalRead (LEFT_POKE) == LOW) { // If left poke is triggered
368398 leftPokeTime = millis ();
369399 LeftCount ++;
370400 leftInterval = 0.0 ;
371401 while (digitalRead (LEFT_POKE) == LOW) {} // Hang here until poke is clear
372402 leftInterval = (millis () - leftPokeTime);
373- Event = " LeftinTimeout" ;
403+ UpdateDisplay ();
404+ Event = " LefinTimeOut" ;
374405 logdata ();
375406 }
376407
@@ -380,29 +411,17 @@ void FED3::Timeout(int seconds) {
380411 rightInterval = 0.0 ;
381412 while (digitalRead (RIGHT_POKE) == LOW) {} // Hang here until poke is clear
382413 rightInterval = (millis () - rightPokeTime);
414+ UpdateDisplay ();
383415 Event = " RightinTimeout" ;
384416 logdata ();
385417 }
386-
387- DateTime now = rtc.now ();
388- unixtime = now.unixtime ();
389-
390- delay (10 );
391-
392- if (unixtime - displayupdate >= 1 ){
393- UpdateDisplay ();
394- display.fillRect (5 , 20 , 200 , 25 , WHITE); // erase the data on screen without clearing the entire screen by pasting a white box over it
395- display.setCursor (6 , 36 );
396- display.print (" Timeout: " );
397- display.print (int (floor (seconds - (unixtime - TimeoutStart))));
398- display.refresh ();
399- displayupdate = now.unixtime ();
400- }
401-
402- Left = false ;
403- Right = false ;
404418 }
405- }
419+
420+ display.fillRect (5 , 20 , 100 , 25 , WHITE); // erase the data on screen without clearing the entire screen by pasting a white box over it
421+ UpdateDisplay ();
422+ Left = false ;
423+ Right = false ;
424+ }
406425
407426/* *************************************************************************************************************************************************
408427 Audio and neopixel stimuli
@@ -1121,11 +1140,11 @@ void FED3::logdata() {
11211140 logfile.println (sqrt (-1 )); // print NaN
11221141 }
11231142
1124- else if ((Event == " Left" ) or (Event == " LeftShort" ) or (Event == " LeftWithPellet" ) or (Event == " LeftinTimeout" )) { //
1143+ else if ((Event == " Left" ) or (Event == " LeftShort" ) or (Event == " LeftWithPellet" ) or (Event == " LeftinTimeout" ) or (Event == " LeftDuringDispense " ) ) { //
11251144 logfile.println (leftInterval/1000.000 ); // print left poke timing
11261145 }
11271146
1128- else if ((Event == " Right" ) or (Event == " RightShort" ) or (Event == " RightWithPellet" ) or (Event == " RightinTimeout" )) { //
1147+ else if ((Event == " Right" ) or (Event == " RightShort" ) or (Event == " RightWithPellet" ) or (Event == " RightinTimeout" ) or (Event == " RightDuringDispense " ) ) { //
11291148 logfile.println (rightInterval/1000.000 ); // print left poke timing
11301149 }
11311150
0 commit comments