mbed_binary_counter

Dependencies:   mbed

Committer:
foivosHrist
Date:
Tue Oct 07 23:55:54 2014 +0000
Revision:
0:858e3371c27e
Child:
1:4e311ab3af04
for LPC1768 platform

Who changed what in which revision?

UserRevisionLine numberNew contents of line
foivosHrist 0:858e3371c27e 1 #include "mbed.h"
foivosHrist 0:858e3371c27e 2 #define PRESSED 0
foivosHrist 0:858e3371c27e 3 #define UNPRESSED 1
foivosHrist 0:858e3371c27e 4
foivosHrist 0:858e3371c27e 5 int getNext();
foivosHrist 0:858e3371c27e 6
foivosHrist 0:858e3371c27e 7 DigitalIn pin8(p8); //button on pin8
foivosHrist 0:858e3371c27e 8 BusOut counter(LED4, LED3, LED2, LED1);
foivosHrist 0:858e3371c27e 9
foivosHrist 0:858e3371c27e 10 //-----------------------------------------------
foivosHrist 0:858e3371c27e 11 int main() {
foivosHrist 0:858e3371c27e 12
foivosHrist 0:858e3371c27e 13 pin8.mode(PullUp); //set internal pullup
foivosHrist 0:858e3371c27e 14
foivosHrist 0:858e3371c27e 15 bool previousState=pin8;
foivosHrist 0:858e3371c27e 16 bool currentState;
foivosHrist 0:858e3371c27e 17
foivosHrist 0:858e3371c27e 18 while(1) {
foivosHrist 0:858e3371c27e 19
foivosHrist 0:858e3371c27e 20 currentState=pin8;
foivosHrist 0:858e3371c27e 21 if(currentState==PRESSED && previousState==UNPRESSED){
foivosHrist 0:858e3371c27e 22 counter=getNext();
foivosHrist 0:858e3371c27e 23
foivosHrist 0:858e3371c27e 24 }
foivosHrist 0:858e3371c27e 25 previousState=currentState;
foivosHrist 0:858e3371c27e 26 wait(0.1);
foivosHrist 0:858e3371c27e 27
foivosHrist 0:858e3371c27e 28
foivosHrist 0:858e3371c27e 29
foivosHrist 0:858e3371c27e 30 }
foivosHrist 0:858e3371c27e 31 }
foivosHrist 0:858e3371c27e 32
foivosHrist 0:858e3371c27e 33
foivosHrist 0:858e3371c27e 34 //-----------------------------------------------
foivosHrist 0:858e3371c27e 35 int getNext(){
foivosHrist 0:858e3371c27e 36 static int i=0;
foivosHrist 0:858e3371c27e 37 if(i==15)i=0;
foivosHrist 0:858e3371c27e 38 else i++;
foivosHrist 0:858e3371c27e 39
foivosHrist 0:858e3371c27e 40 return i;
foivosHrist 0:858e3371c27e 41
foivosHrist 0:858e3371c27e 42 }