Din aplicatia precedenta,cea cu semaforl rutier, mi-a venit ideea sa fac un numarator binar pe 4 biti, conceptul fiind acelasi.
        In primul rand,fiind un numarator binar pe 4 biti,sunt necesare 4 leduri pentru a indica toate numerele binare pe 4 biti adica numerele de la 0 la 15(2^4 numere).
Printr-o rezistenta de 270 ohmi mai conectam un led de la pinul digital 6 la masa,schema electronica ramanand aceeasi cu cea a semaforului.


CODUL SURSA:

    //program NUMARATOR BINAR
int redPin=2;
int yellowPin=3;
int greenPin=4;
int bluePin=6;
int buttonPin=5;
int state=0;
void setup(){
pinMode(redPin,OUTPUT);
pinMode(yellowPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(buttonPin,INPUT);
pinMode(bluePin,OUTPUT);
              }
void loop(){ if(digitalRead(buttonPin)){
  


                           if(state==0){
                             oscilare(LOW,LOW,LOW,HIGH);
                                     state=1;  
                                     }   
                            else if(state==1){
                                              oscilare(LOW,LOW,HIGH,LOW);
                                              state=2;
                                              }
                          else if(state==2){
                                            oscilare(LOW,LOW,HIGH,HIGH);
                                            state=3;
                                            }
                         else if(state==3){
                                           oscilare(LOW,HIGH,LOW,LOW);
                                           state=4;
                                            }
                         else if(state==4){
                                          oscilare(LOW,HIGH,LOW,HIGH);
                                          state=5;
                                          }
                         else if(state==5){
                                           oscilare(LOW,HIGH,HIGH,LOW);
                                           state=6;
                                           } 
                         else if(state==6){
                                            oscilare(LOW,HIGH,HIGH,HIGH);
                                            state=7;
                                           } 
                          else if(state==7){
                                            oscilare(HIGH,LOW,LOW,LOW);
                                            state=8;
                                            } 
                             else if(state==8){
                                               oscilare(HIGH,LOW,LOW,HIGH);
                                               state=9;
                                               }                                       
                               else if(state==9){
                                                 oscilare(HIGH,LOW,HIGH,LOW);
                                                 state=10;
                                                  }
                               else if(state==10){
                                                  oscilare(HIGH,LOW,HIGH,HIGH);
                                                    state=11;
                                                   }
                               else if(state==11){
                                                   oscilare(HIGH,HIGH,LOW,LOW);
                                                   state=12;
                                                    }
                                else if(state==12){
                                                   oscilare(HIGH,HIGH,LOW,HIGH);
                                                   state=13;
                                                   }
                               else if(state==13){
                                                  oscilare(HIGH,HIGH,HIGH,HIGH);
                                                   state=14;
                                                  }
                                else if(state==14){
                                                 oscilare(LOW,LOW,LOW,LOW);
                                                  state=0;                   
                                                  }
delay(500);}
}


void oscilare(int blue,int red,int yellow,int green){
digitalWrite(bluePin,blue);
digitalWrite(redPin,red);
digitalWrite(yellowPin,yellow);
digitalWrite(greenPin,green);
}