_main.ino 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * This is the Arduino code for an:
  3. * Infrared Obstacle Sensor and displaying the time on 6 digital display and serial monitor.
  4. * Uses preprogrammed distance and converting it into mph.
  5. ***Still needs to count and store laps for average #of laps once button press
  6. ***Still needs to use 2 digit separate display the lap count for the above laps once button press
  7. IR Sensor Wiring:
  8. Brown: 5V DC
  9. Blue: GND
  10. Black: Signal, to PIN 3
  11. Arduino pins to the Large Digit Driver IN
  12. Arduino pin for SPEED DISPLAY
  13. 6 -> CLK (GREEN)
  14. 5 -> LAT (BLUE)
  15. 7 -> SER on the IN side (YELLOW)
  16. 5V -> 5V (ORANGE)
  17. Power Arduino with 12V and connect to Vin -> 12V (RED)
  18. GND -> GND (PURPLE)
  19. 8 -> Push Button
  20. START Input
  21. Arduino pin for LAP DISPLAY
  22. 11 -> CLK (GREEN)
  23. 10 -> LAT (BLUE)
  24. 12 -> SER on the IN side (YELLOW)
  25. 5V -> 5V (ORANGE)
  26. Power Arduino with 12V and connect to Vin -> 12V (RED)
  27. GND -> GND (PURPLE)
  28. */
  29. //GPIO declarations
  30. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  31. #define segmentClock 6
  32. #define segmentLatch 5
  33. #define segmentData 7
  34. #define segmentClockLAP 11
  35. #define segmentLatchLAP 10
  36. #define segmentDataLAP 12
  37. #define button 2
  38. // whittier track circumference equals 205.08 feet or 0.0388409091 miles per lap USED 0.0384
  39. // Sabatatini test track circumference equals 100.531 feet or 0.01903996212 miles per lap USED 0.01903
  40. // Iowa track = 0.02083333333 miles per lap
  41. #define distance 0.02083333333
  42. #define maxTimes 13
  43. #define restPeriod 30000
  44. #define MODE_SPINUP 0
  45. #define MODE_COUNTING 1
  46. #define MODE_RESTING 2
  47. #define SENSOR 3 // define pint 3 for sensor
  48. #define ACTION 9 // define pin 9 as for ACTION
  49. int mode = MODE_SPINUP;
  50. float startTime;
  51. float endTime;
  52. float duration;
  53. byte timerRunning;
  54. unsigned long time;
  55. float seconds;
  56. // float minutes;
  57. float hours;
  58. float mph;
  59. int laps = 0;
  60. int avglaps= 0; // AVERAGE LAP COUNTER
  61. unsigned long times[maxTimes] = {0};
  62. int recordedTimes = 0;
  63. unsigned long lastTime = 0;
  64. unsigned long restExpires = 0;