Ver Fonte

Attach button

Kevin Wells há 6 anos atrás
pai
commit
b1382e6934
4 ficheiros alterados com 34 adições e 18 exclusões
  1. 3 14
      loop.ino
  2. 15 4
      main.ino
  3. 11 0
      pushButton.ino
  4. 5 0
      setup.ino

+ 3 - 14
loop.ino

@@ -1,16 +1,3 @@
-
-//GPIO declarations
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-byte segmentClock = 6;
-byte segmentLatch = 5;
-byte segmentData = 7;
-
-byte segmentClockLAP = 11;
-byte segmentLatchLAP = 10;
-byte segmentDataLAP = 12;
-
-
-
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 #define SENSOR 3 // define pint 3 for sensor
 #define ACTION 9 // define pin 9 as for ACTION
@@ -31,7 +18,9 @@ int avglaps= 0; // AVERAGE LAP COUNTER
 
 
 void loop() {
-  
+  // int v = digitalRead(8);
+  // Serial.print(v);
+  // Serial.print('\n');
   if (timerRunning == 0 && digitalRead(SENSOR) == HIGH) { // stop counting
     startTime = millis();
     timerRunning = 1;

+ 15 - 4
main.ino

@@ -10,8 +10,8 @@
 
 IR Sensor Wiring:
 Brown: 5V DC
-Blue:  GNG
-Black: Signal, to PIN 2
+Blue:  GND
+Black: Signal, to PIN 3
 
 Arduino pins to the Large Digit Driver IN
 
@@ -22,7 +22,7 @@ Arduino pin for SPEED DISPLAY
  5V -> 5V (ORANGE)
  Power Arduino with 12V and connect to Vin -> 12V (RED)
  GND -> GND (PURPLE)
- 9 -> Push Button
+ 8 -> Push Button
  START Input 
 
 Arduino pin for LAP DISPLAY
@@ -33,4 +33,15 @@ Arduino pin for LAP DISPLAY
  Power Arduino with 12V and connect to Vin -> 12V (RED)
  GND -> GND (PURPLE)
 
-*/
+*/
+
+//GPIO declarations
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+const byte segmentClock = 6;
+const byte segmentLatch = 5;
+const byte segmentData = 7;
+
+const byte segmentClockLAP = 11;
+const byte segmentLatchLAP = 10;
+const byte segmentDataLAP = 12;
+const byte button = 2;

+ 11 - 0
pushButton.ino

@@ -0,0 +1,11 @@
+void pushButton()
+{
+  static unsigned long last_interrupt_time = 0;
+  unsigned long interrupt_time = millis();
+  // If interrupts come faster than 200ms, assume it's a bounce and ignore
+  if (interrupt_time - last_interrupt_time > 200) 
+  {
+    Serial.print("Button\n");
+  }
+  last_interrupt_time = interrupt_time;
+}

+ 5 - 0
setup.ino

@@ -1,3 +1,5 @@
+
+
 void setup() {
   Serial.begin(9600);// setup Serial Monitor to display information
   pinMode(SENSOR, INPUT_PULLUP);// define pin as Input  sensor
@@ -18,6 +20,9 @@ void setup() {
   digitalWrite(segmentDataLAP, LOW);
   digitalWrite(segmentLatchLAP, LOW);
 
+  pinMode(button, INPUT_PULLUP);
+  attachInterrupt(digitalPinToInterrupt(button), pushButton, RISING);
+