_main.ino 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 maxLaps 12
  43. #define MODE_SPINUP 0
  44. #define MODE_COUNTING 1
  45. #define MODE_RESTING 2
  46. #define SENSOR 3 // define pint 3 for sensor
  47. #define ACTION 9 // define pin 9 as for ACTION
  48. int mode = MODE_SPINUP;
  49. float startTime;
  50. float endTime;
  51. float duration;
  52. byte timerRunning;
  53. unsigned long time;
  54. float seconds;
  55. // float minutes;
  56. float hours;
  57. float mph;
  58. int laps = 0;
  59. int avglaps= 0; // AVERAGE LAP COUNTER
  60. //LAP COUNTER SETUP ///////////////////////////////////////////////////
  61. int recordedLaps = 0; //number of samples averaged
  62. double speeds[maxLaps] = {0}; // need a 0 for every sample to average