Monday, October 5, 2015

MiniProject Process: Code

I found helpful code online that uses a potentiometer to control the brightness of three LEDs, not sure if it does all three at once or does it one at a time I will have to test it today to figure out.


#define ledPin3 11
#define ledPin2 12
#define ledPin1 13
int potpin = 0;
int val;  
void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

void loop()
{ Serial.print(val);
delay(500);
  val = analogRead(potpin);          
  val = map(val, 0, 1023, 0, 179);    
if (val < 178){
  digitalWrite(ledPin1, HIGH);
}  else{
digitalWrite(ledPin1, LOW);
}                 

  if (val < 90 ){
    digitalWrite(ledPin2, HIGH);
  }
else{
digitalWrite(ledPin2, LOW);
}

  if (val < 36 ){
    digitalWrite(ledPin3, HIGH);
  }
else{
digitalWrite(ledPin3, LOW);
}
  delay(15);                          
}

No comments:

Post a Comment