Untitled Post

posted Dec 8, 2009, 8:45 AM by Unknown user
Yesterday, before class ended we got the LED bar graph to work correctly, we had a problem with one of the LED' shorting because it was touching itself but we got all that fixed, and this is our new program we wrote-
int inPin = 1;             // analog 5
int val = 0;                 // where to store info from analog 5
int pin9= 9;
int pin10 = 10;
int pin11 = 11;         // output of red led
int pin12 = 12;
int pin13 = 13;

void setup() {
 
  Serial.begin(9600);
  
for(int pin = 9; pin < 13; pin++)
{
pinMode(pin,OUTPUT); 
}
 
}

void loop() {
 
  val = analogRead(inPin);                    // reads in the values from analog 5 and
                                                                   //assigns them to val
  if(val >= 1){
      
    val = constrain(val, 0, 100);    // mess with these values                                     
      
   
  if(val > 0 && val <= 20)
  {
    digitalWrite(pin13,HIGH);
  }
  else if(val >= 21 && val <= 40)
  {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);
  }
  else if(val >= 41 && val <= 60)
 {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);  
    digitalWrite(pin11,HIGH);
 }
  else if(val >= 61 && val <= 80)
  {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);  
    digitalWrite(pin11,HIGH);
    digitalWrite(pin10,HIGH);
  } 
   else if(val >= 81 && val <=100)
  {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);  
    digitalWrite(pin11,HIGH);
    digitalWrite(pin10,HIGH);
    digitalWrite(pin9,HIGH);
  }
                                               
   }else{           


 
  for(int pin = 9; pin < 13; pin++)
{
digitalWrite(pin,LOW); 
}
    
    
   }
 
 
 Serial.println(val);                               
 

  
  
  
}

Now today and the rest of the week we are going to be adding one more pin to our array board and putting the new LEDs onto the board to give us 30 LED for the bar graph.
Comments