Advertisement
Guest User

Time Study Arduino Assistant

a guest
Jul 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////////////////////////////////
  2. // Time Study Arduino Assistant//
  3. //      By Nicky Fingerle      //
  4. /////////////////////////////////
  5.  
  6. double stopStartTimes [4][5] = { 0 };
  7.  
  8. /*
  9. machine     | 1 | 2 | 3 | 4 | 5 |
  10. lastStop    | - | - | - | - | - |
  11. stopTime    | - | - | - | - | - |
  12. restartTime | - | - | - | - | - |
  13. */
  14.  
  15. double downTimeAndElapsedTime [2][5] = { 0 };
  16.  
  17. /*
  18. machine     | 1 | 2 | 3 | 4 | 5 |
  19. elapsed     | - | - | - | - | - |
  20. downtime    | - | - | - | - | - |
  21. */
  22.  
  23. double logSheet [1000][4];
  24. bool isButtonPressed;
  25. bool isStopped [5] = { 0 };
  26. bool initialized [5] = { 0 };
  27. int universalCount = 0;
  28. int pullDown;
  29.  
  30. void setup()
  31. {
  32.     pinMode( 1, OUTPUT );
  33.     pinMode( 2, OUTPUT );
  34.     pinMode( 3, OUTPUT );
  35.     pinMode( 4, OUTPUT );
  36.     pinMode( 5, OUTPUT );
  37.     pinMode( 6, INPUT );
  38.     pinMode( 7, INPUT );
  39.     pinMode( 8, INPUT );
  40.     pinMode( 9, INPUT );
  41.     pinMode( 10, INPUT );
  42. }
  43.  
  44. void loop()
  45. {
  46.     for ( int i = 1; i < 5; ++i )
  47.     {
  48.         digitalWrite( i, HIGH );
  49.         pullDown = i + 5; //This 5 needs to be increased by 1 for any additional machine
  50.         isButtonPressed = digitalRead( pullDown );
  51.         if ( isButtonPressed == HIGH )
  52.         {
  53.             if ( isStopped [i] == 0 )
  54.             {
  55.                 isStopped [i] = 1;
  56.                 stopStartTimes [1][i] = millis();
  57.                 if ( initialized [i] = 0 )
  58.                 {
  59.                     downTimeAndElapsedTime [0][i] = 0;
  60.                     initialized [i] = 1;
  61.                 }
  62.                 else
  63.                 {
  64.                     downTimeAndElapsedTime [0][i] = (round((stopStartTimes [1][i] - stopStartTimes [0][i]) / 100))/10;
  65.                 }
  66.                 stopStartTimes [0][i] = stopStartTimes [1][i];
  67.             }
  68.             else if ( isStopped [i] == 1 )
  69.             {
  70.                 isStopped [i] = 0;
  71.                 stopStartTimes [2][i] = millis();
  72.                 downTimeAndElapsedTime [1][i] = (round((stopStartTimes [2][i] - stopStartTimes [1][i]) / 100))/10;
  73.                 logSheet [universalCount][0] = universalCount;
  74.                 logSheet [universalCount][1] = 1;
  75.                 logSheet [universalCount][2] = downTimeAndElapsedTime [1][0];
  76.                 logSheet [universalCount][3] = downTimeAndElapsedTime [0][0];
  77.                 //This is where the logging txt sheet and the LCD library come in.
  78.                 universalCount = universalCount + 1;
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement