Light Dimmer

Concept:

  • Replicate the dimming effect from film lights, and the dimmers attached to them that have a slow smooth transition.
const int led1 = 13;
const int led2 = 12;
const int led3 = 11;
const int led4 = 10;
const int led5 = 9;
const int led6 = 8;
const int led7 = 7;
const int led8 = 6;
const int button = 6;

int potpin = A0;
int potnum = 0; //values from potentiometer
int readValue;
int writeValue;

void setup() {
  // put your setup code here, to run once:
  pinMode(button, INPUT_PULLUP);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(potpin, INPUT);
  Serial.begin(9600);
}

void loop() {
  //analog and leds
  readValue = analogRead(potpin);
  writeValue = (255. / 1023.) * readValue;
  // formula from https://toptechboy.com/lesson-11-arduino-circuit-to-dim-led-with-potentiometer/

  //  bool buttonState = digitalRead(button);
  analogWrite(led1, writeValue);
  analogWrite(led2, writeValue);
  analogWrite(led3, writeValue);
  analogWrite(led4, writeValue);
  potnum = analogRead(potpin);
  Serial.println(potnum);
  //digital button and leds
  // put your main code here, to run repeatedly:

  bool buttonState = digitalRead(button);
  Serial.println(button);
  if (buttonState == HIGH) {
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    digitalWrite(led8, LOW);

  } else {

    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);
    digitalWrite(led7, HIGH);
    digitalWrite(led8, HIGH);

  };
}

first attempt

second attempt

 

Leave a Reply