haha yes

Dependencies:   SB1602E mbed

Fork of Taster_Entprellen by Stefan Kummer

Files at this revision

API Documentation at this revision

Comitter:
Lenschinki
Date:
Mon Oct 08 08:04:45 2018 +0000
Parent:
9:a4a4f8cc4019
Commit message:
Taster Entprellen

Changed in this revision

DEBOUNCE/debounceIn.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a4a4f8cc4019 -r ba816c404c3c DEBOUNCE/debounceIn.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DEBOUNCE/debounceIn.h	Mon Oct 08 08:04:45 2018 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+
+class debounceIn : public DigitalIn
+{
+public:
+    /* Liest den entprellten Schattenwert des Pins */
+    int read(void)
+    {
+        return shadow;
+    }
+    
+    /* Stellt ein, wie oft der Pin als 1 bzw. als 0 gelesen werden muss um den Schatten-Zustand zu Schalten */
+    void setSamples(int i)
+    {
+        samples = i;   
+    }
+    
+    void setDebounce_us(int us)
+    {
+       ticker.attach_us(callback(this,&debounceIn::cb),us);
+    }
+    
+    /* Konstruktor */
+    debounceIn(PinName pin ) : DigitalIn(pin)
+    {   }
+protected:
+    void cb()
+    {
+        if(DigitalIn::read())
+        {
+            if(counter < samples) counter++;
+            if(counter == samples) shadow = 1;
+        }
+        else
+        {
+            if(counter > 0) counter--;
+            if(counter == 0) shadow = 0;        
+        }            
+    }       
+    int shadow;
+    int counter;
+    int samples;
+    Ticker ticker;
+};
+    
\ No newline at end of file
diff -r a4a4f8cc4019 -r ba816c404c3c main.cpp
--- a/main.cpp	Sun Sep 30 21:21:20 2018 +0000
+++ b/main.cpp	Mon Oct 08 08:04:45 2018 +0000
@@ -1,25 +1,58 @@
 #include "mbed.h"
 #include "SB1602E.h"
+#include "debounceIn.h"
 #define USE_I2C_2V8
 
 DigitalOut myled(P0_8); // 7=rot, 8=grün, 9=blau
-DigitalIn sw_o(P0_12);
-DigitalIn sw_b(P0_13);
-DigitalIn sw_g(P0_14);
+//DigitalIn sw_o(P0_12);
+//DigitalIn sw_b(P0_13);
+//DigitalIn sw_g(P0_14);
+
+InterruptIn redButton(P0_12);
+InterruptIn blueButton(P0_13);
+InterruptIn greenButton(P0_14);
 
 I2C i2c_disp(P0_5, P0_4); //  SDA, SCL auf LPC11U24
 SB1602E lcd(i2c_disp);
 
 int count_o, count_b, count_g = 0;
 
+void btnRedPressed()
+{
+    wait_us(200);
+    if(redButton == 0)
+        count_o++;    
+}
+
+void btnBluePressed()
+{
+    wait_us(200);
+    if(blueButton == 0)
+        count_b++;    
+}
+
+void btnGreenPressed()
+{
+    wait_us(200);
+    if(greenButton == 0)
+        count_g++;    
+}
+
 int main()
 {
     lcd.printf(0, "Red Blue Green\r");    //  Parameter von printf auf LCD: Zeilennummer (0 or 1), string
-    while(1) {
-
+    
+    redButton.mode(PullUp);
+    blueButton.mode(PullUp);
+    greenButton.mode(PullUp);
+    
+    redButton.fall(&btnRedPressed);
+    blueButton.fall(&btnBluePressed);
+    greenButton.fall(&btnGreenPressed);
+    
+    while(1) 
+    {
         lcd.printf( 1,1, "%d   %d   %d", count_o, count_b, count_g);
-
         myled = !myled;
-
     }
 }
\ No newline at end of file