About

Garrett

Bio: I'm an enthusiastic tinkerer who loves to discover new ways to apply technology. I'm driven to work in environments where creativity and technology connect, leading to improvements that can help many people in different capacities.

View complete profile

 

4 thoughts on “About

  1. Hi, i have been trying to find code for controlling color of led strip with rotary switch like in your project (HALLWAY LIGHTING WITH LED STRIPS”. Is it possible to get this code you used from you? Thanx!

    Like

    1. Hello Ali,
      I could not find the code that I used on my LED encoder project, but I found the code that I started with. After getting this to work with a potentiometer, I adapted it to work with an encoder using Paul Stoffregen’s Encoder Library


      /*
      * Code for making one potentiometer control 3 LEDs, red, grn and blu, or one tri-color LED
      * The program cross-fades from red to grn, grn to blu, and blu to red
      * Clay Shirky
      */

      // INPUT: Potentiometer should be connected to 5V and GND
      int potPin = 3; // Potentiometer output connected to analog pin 3
      int potVal = 0; // Variable to store the input from the potentiometer

      // OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
      // LED's cathodes should be connected to digital GND
      int redPin = 9; // Red LED, connected to digital pin 9
      int grnPin = 10; // Green LED, connected to digital pin 10
      int bluPin = 11; // Blue LED, connected to digital pin 11

      // Program variables
      int redVal = 0; // Variables to store the values to send to the pins
      int grnVal = 0;
      int bluVal = 0;

      void setup()
      {
      pinMode(redPin, OUTPUT); // sets the pins as output
      pinMode(grnPin, OUTPUT);
      pinMode(bluPin, OUTPUT);
      }

      // Main program
      void loop()
      {
      potVal = analogRead(potPin); // read the potentiometer value at the input pin

      if (potVal < 341) // Lowest third of the potentiometer's range (0-340)
      {
      potVal = (potVal * 3) / 4; // Normalize to 0-255

      redVal = 256 - potVal; // Red from full to off
      grnVal = potVal; // Green from off to full
      bluVal = 1; // Blue off
      }
      else if (potVal < 682) // Middle third of potentiometer's range (341-681)
      {
      potVal = ( (potVal-341) * 3) / 4; // Normalize to 0-255

      redVal = 1; // Red off
      grnVal = 256 - potVal; // Green from full to off
      bluVal = potVal; // Blue from off to full
      }
      else // Upper third of potentiometer"s range (682-1023)
      {
      potVal = ( (potVal-683) * 3) / 4; // Normalize to 0-255

      redVal = potVal; // Red from off to full
      grnVal = 1; // Green off
      bluVal = 256 - potVal; // Blue from full to off
      }
      analogWrite(redPin, redVal); // Write values to LED pins
      analogWrite(grnPin, grnVal);
      analogWrite(bluPin, bluVal);
      }

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s