Go Down

Topic: What does a 15 bit color code look like? (Read 5163 times) previous topic - next topic

Qdeathstar

OH!  I get it now

That is a great idea, a lot easier way of finding a color than manually changing the color codes one at a time.
A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

Qdeathstar

#16
Aug 16, 2014, 08:17 am Last Edit: Aug 16, 2014, 08:31 am by Qdeathstar Reason: 1
Thanks for the tip, this will make finding colors so much easier.



Code: [Select]

#include <TimerOne.h>
#include "LPD6803.h"

//Example to control LPD6803-based RGB LED Modules in a strand
// Original code by Bliptronics.com Ben Moyes 2009
//Use this as you wish, but please give credit, or at least buy some of my LEDs!

// Code cleaned up and Object-ified by ladyada, should be a bit easier to use

/*****************************************************************************/

// Choose which 2 pins you will use for output.
// Can be any valid output pins.
int dataPin = 4;       // 'yellow' wire
int clockPin = 5;      // 'green' wire
// Don't forget to connect 'blue' to ground and 'red' to +5V
long int q = 0;
long int m = 0;
int redpotPin = A2;
int bluepotPin = A3;
int greenpotPin = A4;
int color;
int numpix = 50;
// Timer 1 is also used by the strip to send pixel clocks

// Set the first variable to the NUMBER of pixels. 20 = 20 pixels in a row
LPD6803 strip = LPD6803(numpix, dataPin, clockPin);


void setup() {

  Serial.begin(9600);

  strip.setCPUmax(60);  // start with 50% CPU usage. up this if the strand flickers or is slow

  // Start up the LED counter
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}


void loop() {

  pots();
  Serial.println(color);
 
  for (q=0; q < numpix; q++){
  strip.setPixelColor(q, color);

  strip.show();   // write all the pixels out
  //Serial.println(q);
 
  /*if (q > 50) {
    while (m < 50) {
    strip.setPixelColor(m, color);
    delay (100);
    m = m + 1;
    q = 0;
    strip.show();
    }
  }
  m = 0;*/
  //if (q < numpix) {
  //q = q + 1;
  //}
  delay (40);
 
}
}


int pots() {
int Red = analogRead(redpotPin) >> 5;
int Green = analogRead(greenpotPin) >> 5;
int Blue = analogRead(bluepotPin) >> 5;

color = Blue*1024 + Red*32 + Green;
//Serial.println(color);
//return color;
}




Do you have to debounce the potentiometers? Because, if i don't have a delay of at least 40, the lights toward the end of the strip flicker?
Code: [Select]

#include <TimerOne.h>
#include "LPD6803.h"

//Example to control LPD6803-based RGB LED Modules in a strand
// Original code by Bliptronics.com Ben Moyes 2009
//Use this as you wish, but please give credit, or at least buy some of my LEDs!

// Code cleaned up and Object-ified by ladyada, should be a bit easier to use

/*****************************************************************************/

// Choose which 2 pins you will use for output.
// Can be any valid output pins.
int dataPin = 4;       // 'yellow' wire
int clockPin = 5;      // 'green' wire
// Don't forget to connect 'blue' to ground and 'red' to +5V
long int q = 0;
long int m = 0;
int redpotPin = A2;
int bluepotPin = A3;
int greenpotPin = A4;
int color;
// Timer 1 is also used by the strip to send pixel clocks

// Set the first variable to the NUMBER of pixels. 20 = 20 pixels in a row
LPD6803 strip = LPD6803(50, dataPin, clockPin);


void setup() {

 Serial.begin(9600);

 strip.setCPUmax(60);  // start with 50% CPU usage. up this if the strand flickers or is slow

 // Start up the LED counter
 strip.begin();

 // Update the strip, to start they are all 'off'
 strip.show();
}


void loop() {

 pots();
 Serial.println(color);
 strip.setPixelColor(q, color);

 strip.show();   // write all the pixels out
 //Serial.println(q);
 
 if (q > 50) {
   while (m < 50) {
   strip.setPixelColor(m, color);
   delay (100);
   m = m + 1;
   q = 0;
   strip.show();
   }
 }
 m = 0;
 q = q + 1;
 delay (100);
}


int pots() {
int Red = analogRead(redpotPin) >> 5;
int Green = analogRead(greenpotPin) >> 5;
int Blue = analogRead(bluepotPin) >> 5;

color = Blue*1024 + Red*32 + Green;
//Serial.println(color);
//return color;
}

A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

Qdeathstar

Also, what if i wanted to make blue's upper limit less than the upper limit of red and green? 

And can you explain how

int Red = analogRead(redpotPin) >> 5;

turns the 1023 value into 31?  <magic.

I know it has something to do with shifting bytes.....

1010101  being turned into 10 but i still don't understand how it turns into 31...
A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

AWOL

1023 = 210 - 1.
31 = 25 - 1

">> x" divides by 2x, so 1023 / 32 = 31.

Go Up