포텐쇼미터로 LED 밝기 개수를 조절해본다.

 

int pins_LED[] = {2,3,4,5};
int vRegistor = A0;

void setup() {
  Serial.begin(9600);
  pinMode(vRegistor, INPUT);
  for(int i=0;i<4;i++){
    pinMode(pins_LED[i],OUTPUT);
    digitalWrite(pins_LED[i],LOW);
  }
}

void loop() {
  int adc = analogRead(vRegistor);
  int count_led = (adc>>8)+1;

  for(int i=0; i<4; i++){
    if(i<count_led)
      digitalWrite(pins_LED[i],HIGH);
    else
      digitalWrite(pins_LED[i],LOW);
  }
  Serial.println(String("ADC : ") + adc + ", LED count : " + count_led);

  delay(1000);
}

 

 

+ Recent posts