LED Counter

LED counter

Team -
Ashwini Sukhdeve
Manisha Iyer
Shilpi Seth
Sushmita Kari
Swati Asthana

1st assignment on arduino

The Program

/*
Numbers
This displays numbers from 0 to 9 using 13 LEDs 

 */
  const int buttonPin = 12; 
  int buttonState = HIGH;  
  int reading;           
  int previous = LOW;
  int count = 9;
  int pinOut[11];
  long time = 0;         
  long debounce = 200;   

void setup() {                
  for( int i = 1; i < 12; i++) {
    pinMode(i,OUTPUT);
  }

  pinMode(buttonPin, INPUT);  
 }

void loop()
{
  reading = digitalRead(buttonPin);

  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
//  if (reading != previous) {
     if(count == 9) {
       count = 0;
     }
     else {
       count = count++;
     }
    time = millis();
    PresentCount(count);
  }
  previous = reading;
}

void PresentCount( int x ) {

if (x == 0) {
 //0
 for( int i = 1; i < 12; i++) {
   if(i == 11) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}

//1
else if (x == 1) {
   for( int i = 1; i < 12; i++) {
   if(i == 1 || i == 2 || i == 6 || i == 7 || i == 8 || i == 9 || i == 10 || i == 11 ) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}  

 //2  
 else if (x == 2) {
   for( int i = 1; i < 12; i++) {
   if(i == 5 || i == 10) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}

 else if (x == 3) {
   for( int i = 1; i < 12; i++) {
   if(i == 8 || i == 10) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}

 else if (x == 4) {
   for( int i = 1; i < 12; i++) {
   if(i == 2 || i == 6 || i == 7 || i == 8) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}

 else if (x == 5) {
   for( int i = 1; i < 12; i++) {
   if(i == 4 || i == 8) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}

 else if (x == 6) {
   for( int i = 1; i < 12; i++) {
   if(i == 4) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}

else if (x == 7) {
   for( int i = 1; i < 12; i++) {
   if(i == 6 || i == 7 || i == 8 || i == 9 || i == 10 || i == 11 ) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}

else if (x == 8) {
   for( int i = 1; i < 12; i++) {
       digitalWrite(i,HIGH);
   }
}

 else {
   for( int i = 1; i < 12; i++) {
   if(i == 8) {
    digitalWrite(i,LOW);
   }
   else {
     digitalWrite(i,HIGH);
   }
  }
}
}
Bibliography
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License