Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Hackster Cafe: Open Hardware Summit. Watch the stream live on Friday!Hackster is hosting Hackster Cafe: Open Hardware Summit. Stream on Friday!
kpower
Published © GPL3+

Arduino controlled dual dimmable light array

Make an Arduino controlled light array that alternatively dims and lights LED diodes with a compensated voltage giving a cool visual display

BeginnerFull instructions provided2 hours120
Arduino controlled dual dimmable light array

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Mega-B Development Kit
Breadware Inc Mega-B Development Kit
×1
LED (generic)
LED (generic)
×6
MC74HC14A Hex Schmitt-Trigger Inverter
×1
Resistor 220 ohm
Resistor 220 ohm
×6

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

Dual Fading Light Array

Arduino
/*
  Fading

  This example shows how to fade two LED arrays alternatively using the analogWrite() function
  and the MC74HC14 Hex Schmitt Trigger Inverter

  The circuit:
  - Digital pin 9 attached to input to first Schmitt Trigger
  - First LED attached to output of first Schmitt Trigger through 220 Ohmn resistor
  - Output also connected to input of second Schmitt Trigger
  - Second LED attached to output of second Schmitt Trigger
  - And so on...

  Generate numbers that more closly follow LED dimming and lighting cycle

  Use numbers between 0 and 255 that have been fitted to curve
  (m^x -1)/(m-1)

*/

int ledPin = 9;  // MC74HC14 connected to digital pin 9
float mValue = 6.0;
float factor;
float result;
int fadeValue;

void setup() {
  // Serial.begin(115200);
  pinMode(ledPin, OUTPUT);  // Set the pin as output
}

void loop() {
  // fade in from min to max in increments of 0.05 points:
  for (float x = 0.0; x <= 1.01; x += 0.05) {
    factor = (pow(mValue,x)-1)/(mValue-1); // apply compensation formula
    result = factor*255.0;
    // convert float variable to integer
    fadeValue = int(result);
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 80 milliseconds to see the brightning effect
    delay(80);
  }
  delay(800);

  // fade out from max to min in increments of 0.05 points:
  for (float x = 1.0; x >= -0.01; x -= 0.05) {
    factor = (pow(mValue,x)-1)/(mValue-1); // apply compensation formula
    result = factor*255.0;
    // convert float variable to integer
    fadeValue = int(result);
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 80 milliseconds to see the dimming effect
    delay(80);
  }
  delay(900);

}

Credits

kpower
19 projects • 6 followers
Qualified Electrical Engineer with experience in software and hardware development
Contact

Comments

Please log in or sign up to comment.