Science 3DJLCPCB
Published © GPL3+

Photographer's LED bar

This LED bar allows creative photographers to enhance their creativity by lighting their subject at specific location and with a color

IntermediateShowcase (no instructions)8 hours371
Photographer's LED bar

Things used in this project

Hardware components

NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
JLCPCB Customized PCB
JLCPCB Customized PCB
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fusion 360
Autodesk Fusion 360
Autodesk EAGLE
Autodesk EAGLE

Hand tools and fabrication machines

Creality CR 10 S5
CNC - Shapeoko 3

Story

Read more

Code

LED BAR

Arduino
code to paste in a new Arduino Project
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN        4 // On Trinket or Gemma, suggest changing this to 1

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 24 // Popular NeoPixel ring size

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int LED_Brightness;

int booting = 1;

//// SWITCH B1 ////
static const int B1_buttonPin = 3;  // pull down
int B1_buttonStatePrevious = LOW;                      // previousstate of the switch
unsigned long minB1_buttonLongPressDuration = 3000;    // Time we wait before we see the press as a long press
unsigned long B1_buttonLongPressMillis;                // Time in ms when we the B1_button was pressed
bool B1_buttonStateLongPress = false;                  // True if it is a long press
const int intervalB1_button = 50;                      // Time between two readings of the B1_button state
unsigned long previousB1_buttonMillis;                 // Timestamp of the latest reading
unsigned long B1_buttonPressDuration;                  // Time the B1_button is pressed in ms
unsigned long currentMillis;          // Variabele to store the number of milleseconds since the Arduino has started
bool B1_button_Current_State = LOW; //current state, change when clicked
bool B1_button_Current_LongPressed_State = LOW; //current state, change when clicked
int LED_COLOR_MODE = 0;
int LED_Brightness_Lowest = 20;
int POT_Pin =   A1;    // A1 sur trinket 5v = Pin #2
int POT_Value = 0;  // variable to store the value coming from the sensor

void setup()
{
  //// SWITCH B1 ////
  pinMode(B1_buttonPin, INPUT);          // set B1_buttonPin as input
  pinMode(LED_BUILTIN, OUTPUT);

  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.

  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}

void loop()
{
  if (booting == 1)
    goBooting();

  currentMillis = millis();    // store the current time
  //// SWITCH B1 ////
  readB1_buttonState();           // read the B1_button state

  // to check the short pressed button state
  digitalWrite(LED_BUILTIN, B1_button_Current_State);
  
  POT_Value = analogRead(POT_Pin);
  LED_Brightness = map(POT_Value, 0 , 1023 , LED_Brightness_Lowest, 255);
  //LED_Brightness=255;
  //  pixels.clear(); // Set all pixel colors to 'off'
  switch (LED_COLOR_MODE)
  {
    case 0:
      for (int i = 0; i < NUMPIXELS; i++)
      {
        pixels.setPixelColor(i, pixels.Color(LED_Brightness, LED_Brightness, LED_Brightness));
      }
      break;
    case 1:
      for (int i = 0; i < NUMPIXELS; i++)
      {
        pixels.setPixelColor(i, pixels.Color(LED_Brightness, 0, 0));
      }
      break;
    case 2:
      for (int i = 0; i < NUMPIXELS; i++)
      {
        pixels.setPixelColor(i, pixels.Color(0, LED_Brightness, 0));
      }
      break;
    case 3:
      for (int i = 0; i < NUMPIXELS; i++)
      {
        pixels.setPixelColor(i, pixels.Color(0, 0, LED_Brightness));
      }
      break;
    case 4:
      for (int i = 0; i < NUMPIXELS; i++)
      {
        pixels.setPixelColor(i, pixels.Color(0, LED_Brightness, LED_Brightness));
      }
      break;
    case 5:
      for (int i = 0; i < NUMPIXELS; i++)
      {
        pixels.setPixelColor(i, pixels.Color(LED_Brightness, 0 , LED_Brightness));
      }
      break;
    case 6:
      for (int i = 0; i < NUMPIXELS; i++)
      {
        pixels.setPixelColor(i, pixels.Color(LED_Brightness, LED_Brightness, 0 ));
      }
      break;
  }
  pixels.show();   // Send the updated pixel colors to the hardware.

  // LOOP END
}



// Function for reading the B1_button state
void readB1_buttonState()
{
  /*
     Bas on Tech - LONG PRESS B1_button
     This course is part of the courses on https://arduino-tutorials.net

     (c) Copyright 2019 - Bas van Dijk / Bas on Tech
     This code and course is copyrighted. It is not allowed to use these courses commercially
     without explicit written approval

     YouTube:    https://www.youtube.com/c/BasOnTech
     Facebook:   https://www.facebook.com/BasOnTechChannel
     Instagram:  https://www.instagram.com/BasOnTech
     Twitter:    https://twitter.com/BasOnTech

  */

  // If the difference in time between the previous reading is larger than intervalB1_button
  if (currentMillis - previousB1_buttonMillis > intervalB1_button) {

    // Read the digital value of the B1_button (LOW/HIGH)
    int B1_buttonState = digitalRead(B1_buttonPin);

    // If the B1_button has been pushed AND
    // If the B1_button wasn't pressed before AND
    // IF there was not already a measurement running to determine how long the B1_button has been pressed
    if (B1_buttonState == HIGH && B1_buttonStatePrevious == LOW && !B1_buttonStateLongPress) {
      B1_buttonLongPressMillis = currentMillis;
      B1_buttonStatePrevious = HIGH;
      B1_button_Current_State = !B1_button_Current_State;
      LED_COLOR_MODE++;
      if (LED_COLOR_MODE > 6)
        LED_COLOR_MODE = 0;
      //Serial.println("B1_button pressed");
    }

    // Calculate how long the B1_button has been pressed
    B1_buttonPressDuration = currentMillis - B1_buttonLongPressMillis;

    // If the B1_button is pressed AND
    // If there is no measurement running to determine how long the B1_button is pressed AND
    // If the time the B1_button has been pressed is larger or equal to the time needed for a long press
    if (B1_buttonState == HIGH && !B1_buttonStateLongPress && B1_buttonPressDuration >= minB1_buttonLongPressDuration) {
      B1_buttonStateLongPress = true;
      B1_button_Current_LongPressed_State = !B1_button_Current_LongPressed_State;
      //Serial.println("B1_button long pressed");
    }

    // If the B1_button is released AND
    // If the B1_button was pressed before
    if (B1_buttonState == LOW && B1_buttonStatePrevious == HIGH) {
      B1_buttonStatePrevious = LOW;
      B1_buttonStateLongPress = false;
      //     digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
      //Serial.println("B1_button released");

      // If there is no measurement running to determine how long the B1_button was pressed AND
      // If the time the B1_button has been pressed is smaller than the minimal time needed for a long press
      if (!B1_buttonStateLongPress && B1_buttonPressDuration < minB1_buttonLongPressDuration) {
        //Serial.println("B1_button pressed shortly");
      }
    }

    // store the current timestamp in previousB1_buttonMillis
    previousB1_buttonMillis = currentMillis;

  }

}

void goBooting()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(55);
  digitalWrite(LED_BUILTIN, LOW);
  delay(111);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(55);
  digitalWrite(LED_BUILTIN, LOW);
  delay(111);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(55);
  digitalWrite(LED_BUILTIN, LOW);
  digitalWrite(LED_BUILTIN, LOW);
  booting = 0;
}

Credits

Science 3D

Science 3D

11 projects • 25 followers
I have a background in electronics, since 1984. I used to work as a programmer for a couple of years. Now, I am working as a DBA.
JLCPCB

JLCPCB

68 projects • 38 followers
JLCPCB, is the largest PCB and PCB Assembly prototype enterprise in Asia. Coupon code "JLCPCBcom" for all and permanantly available.

Comments