counter is made using 7 segment display to count repeatedly from 0 to a specific value.

Dependencies:   mbed

Revision:
0:6cb676e4dee1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 27 16:56:19 2013 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+
+AnalogIn ain(p20);      //interrupt pin
+  
+DigitalOut led[]= {p19,p18,p17,p16,p15,p14,p13,p12};   //b,a,f,g,e,d,c,dp
+
+int number[11][8]= {
+    {1,1,1,0,1,1,1,0},      // 0
+    {1,0,0,0,0,0,1,0},      // 1
+    {1,1,0,1,1,1,0,0},      // 2
+    {1,1,0,1,0,1,1,0},      // 3
+    {1,0,1,1,0,0,1,0},      // 4
+    {0,1,1,1,0,1,1,0},      // 5
+    {0,1,1,1,1,1,1,0},      // 6
+    {1,1,0,0,0,0,1,0},      // 7
+    {1,1,1,1,1,1,1,0},      // 8
+    {1,1,1,1,0,1,1,0},      // 9
+    {0,0,0,0,0,0,0,1}       // dp
+};
+
+//function for glowing seven segment display
+int glow(int no)
+{
+    for(int i=0; i<8; i++)
+        led[i]=number[no][i];    
+    return 1;
+}
+
+int main()
+{
+    int j = 0; // Set counter to zero
+    
+    float x;
+    
+    while (1) {
+        if(j>5)  // Count to a maximum no 5
+           j=0;
+         
+        x=ain.read();
+        
+        if (x > 0.35) {
+            glow(++j);  //Increment the counter whenever voltage at interrupt pin is greater than a threshold (in my case it is 0.35)
+            wait(2);
+        } 
+        else
+            glow(j);
+    }
+}
\ No newline at end of file