ulvis.paste.net

Paste Search Dynamic
Recent pastes
sketch reaction speed test
  1. #include <TM1637Display.h>
  2.  
  3. #define LED 10
  4. #define BTN 8
  5.  
  6. #define CLK 3
  7. #define DIO 2
  8.  
  9. TM1637Display display(CLK, DIO);
  10. uint8_t segments[] = {0x40, 0x40, 0x40, 0x40};
  11.  
  12. void setup() {
  13.   pinMode(LED, OUTPUT);
  14.   pinMode(BTN, INPUT);
  15.  
  16.   display.setBrightness(0x04);
  17. }
  18.  
  19. int ledTStmp, buttonTStmp;
  20.  
  21. void loop() {
  22.   display.setSegments(segments); // display idle sign
  23.  
  24.   digitalWrite(LED, 1);
  25.   delay(random(1000, 10000));
  26.   digitalWrite(LED, 0);
  27.  
  28.   ledTStmp = millis();
  29.   while (digitalRead(BTN) != 1) { ; } // press button to continue
  30.   buttonTStmp = millis();
  31.  
  32.   display.showNumberDec(buttonTStmp - ledTStmp); // display reaction time
  33.   delay(1000);                        // wait until button released
  34.   while (digitalRead(BTN) != 1) { ; } // press button to continue
  35. }
Parsed in 0.005 seconds