KFMAKR
June 10, 2019, 8:35am
#1
Hi everyone,
I’m working with a strip led DotStart, It’s build with SMD5050 APA102 and 3 white led.
I would like to control the grey rate or intensity through the color variable.
it’s define on uint32_t and concat the 3 Led rates: 0xRed + 0xGreen + 0xBlue
I tried the following sequence but it doesn’t work, even if I change the switch… I never reach the right result.
In this example I should transmit color = 0xFF00FF, but here the result is 0xFF… so only one led inside the SMD5050 is activated.
How proceed?
Led1hex = 255;
Led2hex = 0;
Led3hex = 255;
uint32_t color = ( (Led1hex << 0) | (Led2hex << 8) | (Led3hex << 16) ) ;
Serial.print(color,HEX);
Can’t tell because of the missing portion of your code, but if Led3hex is defined as an integer the result of left shifting it 16 bits will be 0x00, if Led2hex and Led3hex are defined as bytes, left shifting them will always result in 0x00.
Try the following statement:
uint32_t color = ( (uint32_t)(Led1hex << 0) | (uint32_t)(Led2hex << 8) | (uint32_t)(Led3hex << 16) ) ;
KFMAKR
June 10, 2019, 2:11pm
#3
It still doesn’t work only one led is powered.
I added the full sketch below.
We should transmit FF00FF but the answer is just FF
#include <Adafruit_DotStar.h>
#include <SPI.h>
#include <SparkFunTSL2561.h>
#include <Wire.h>
#define NUMPIXELS 1
#define DATAPIN 12
#define CLOCKPIN 13
uint8_t Led1hex;
uint8_t Led2hex;
uint8_t Led3hex;
Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
SFE_TSL2561 light;
boolean gain; // Gain setting, 0 = X1, 1 = X16;
unsigned int ms; // Integration ("shutter") time in milliseconds
void setup() {
Serial.begin(9600);
Serial.println("TSL2561 example sketch");
light.begin();
unsigned char ID;
if (light.getID(ID))
{
Serial.print("Got factory ID: 0X");
Serial.print(ID,HEX);
Serial.println(", should be 0X5X");
}
else
{
byte error = light.getError();
printError(error);
}
gain = 0;
unsigned char time = 2;
Serial.println("Set timing...");
light.setTiming(gain,time,ms);
Serial.println("Powerup...");
light.setPowerUp();
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif
strip.begin(); // Initialize pins for output
strip.show(); // Turn all LEDs off ASAP
}
int head = 0;
//====================================================================================================
void loop() {
Led1hex = 255;
Led2hex = 0;
Led3hex = 255;
//uint32_t color = 0xFF00FF;
uint32_t color = ( (uint32_t)(Led1hex << 0) | (uint32_t)(Led2hex << 8) | (uint32_t)(Led3hex << 16) ) ;
Serial.print(color,HEX);
strip.setPixelColor(0, color); strip.show();
delay(ms);
unsigned int data0, data1;
if (light.getData(data0,data1))
{
Serial.print("data0: ");
Serial.print(data0);
Serial.print(" data1: ");
Serial.print(data1);
double lux; // Resulting lux value
boolean good; // True if neither sensor is saturated
good = light.getLux(gain,ms,data0,data1,lux);
Serial.print(" lux: ");
Serial.print(lux);
if (good) Serial.println(" (good)"); else Serial.println(" (BAD)");
}
else
{
byte error = light.getError();
printError(error);
}
}
//====================================================================================================
void printError(byte error)
{
Serial.print("I2C error: ");
Serial.print(error,DEC);
Serial.print(", ");
switch(error)
{
case 0:
Serial.println("success");
break;
case 1:
Serial.println("data too long for transmit buffer");
break;
case 2:
Serial.println("received NACK on address (disconnected?)");
break;
case 3:
Serial.println("received NACK on data");
break;
case 4:
Serial.println("other error");
break;
default:
Serial.println("unknown error");
}
}
Oops, I got the parenthesis wrong, have to change the variable to 32 bit, not the result:
uint32_t color = ( ((uint32_t)Led1hex << 0) | ((uint32_t)Led2hex << 8) | ((uint32_t)Led3hex << 16) ) ;
KFMAKR
June 10, 2019, 3:04pm
#5
Cool!!! It's running thanks for your help