mbed_binary_counter

Dependencies:   mbed

main.cpp

Committer:
foivosHrist
Date:
2014-10-07
Revision:
0:858e3371c27e
Child:
1:4e311ab3af04

File content as of revision 0:858e3371c27e:

#include "mbed.h"
#define PRESSED 0
#define UNPRESSED 1

int getNext();

DigitalIn pin8(p8); //button on pin8
BusOut counter(LED4, LED3, LED2, LED1);
 
//----------------------------------------------- 
int main() {
    
    pin8.mode(PullUp); //set internal pullup
    
    bool previousState=pin8;
    bool currentState;
   
    while(1) {
        
        currentState=pin8;
        if(currentState==PRESSED && previousState==UNPRESSED){
              counter=getNext();  
            
        }
        previousState=currentState;
        wait(0.1);
        
        
        
    }
}


//-----------------------------------------------
int getNext(){
    static int i=0;
    if(i==15)i=0;
    else i++;
    
    return i;
    
    }