/* * This is the Arduino code for an: * Infrared Obstacle Sensor and displaying the time on 6 digital display and serial monitor. * Uses preprogrammed distance and converting it into mph. ***Still needs to count and store laps for average #of laps once button press ***Still needs to use 2 digit separate display the lap count for the above laps once button press IR Sensor Wiring: Brown: 5V DC Blue: GND Black: Signal, to PIN 3 Arduino pins to the Large Digit Driver IN Arduino pin for SPEED DISPLAY 6 -> CLK (GREEN) 5 -> LAT (BLUE) 7 -> SER on the IN side (YELLOW) 5V -> 5V (ORANGE) Power Arduino with 12V and connect to Vin -> 12V (RED) GND -> GND (PURPLE) 8 -> Push Button START Input Arduino pin for LAP DISPLAY 11 -> CLK (GREEN) 10 -> LAT (BLUE) 12 -> SER on the IN side (YELLOW) 5V -> 5V (ORANGE) Power Arduino with 12V and connect to Vin -> 12V (RED) GND -> GND (PURPLE) */ //GPIO declarations //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #define segmentClock 6 #define segmentLatch 5 #define segmentData 7 #define segmentClockLAP 11 #define segmentLatchLAP 10 #define segmentDataLAP 12 #define button 2 // whittier track circumference equals 205.08 feet or 0.0388409091 miles per lap USED 0.0384 // Sabatatini test track circumference equals 100.531 feet or 0.01903996212 miles per lap USED 0.01903 // Iowa track = 0.02083333333 miles per lap #define distance 0.02083333333 #define maxTimes 13 #define restPeriod 30000 #define MODE_SPINUP 0 #define MODE_COUNTING 1 #define MODE_RESTING 2 #define SENSOR 3 // define pint 3 for sensor #define ACTION 9 // define pin 9 as for ACTION int mode = MODE_SPINUP; float startTime; float endTime; float duration; byte timerRunning; unsigned long time; float seconds; // float minutes; float hours; float mph; int laps = 0; int avglaps= 0; // AVERAGE LAP COUNTER unsigned long times[maxTimes] = {0}; int recordedTimes = 0; unsigned long lastTime = 0; unsigned long restExpires = 0;