leonvandenbeukel / 7-Segment-Digital-Clock-V2

A new version of a large 3D printed 7 segment digital clock with LED's
94 stars 54 forks source link

Cannot change the color in the displayNumber subroutine #23

Open billbrach opened 3 months ago

billbrach commented 3 months ago

I have taken your "7-Segment-Clock.ino" sketch and gutted out everything not necessary to display a number on a 5 X 5 LED matrix. I built 25 bit long numbers, to match the layout of the 5 X 5 LED matrix I bought off of Aliexpress. The problem is I cannot change the color in the displayNumber() routine. In the middle of loop(), try changing the CRGB colr line to something w/o Red. You don't necessarily need a 5 X 5 matrix to test this, any WS2812B strip should work, it just won't display the numbers correctly.

I think the problem is in this line, which I don't fully understand: LEDs[i + startindex] = ((numbers[number] & 1 << i) == 1 << i) ? color : alternateColor;

Hopefully it is just a stupid mistake on my part !! THANKS !!

Here is my code:

// CODE START // Demo code for a 5 X 5 WS2812B matrix, purchased from Aliexpress

// Based on the code here: https://github.com/leonvandenbeukel/7-Segment-Digital-Clock-V2/tree/master/7-Segment-Clock // but with all non-essential code removed so as to have demo code that only displays the digits 0 thru 9 on a 5x5 matrix

// 5X5 LED matrix from Aliexpress /* "as the ox plows" coded rows and columns

include

include

define NUM_LEDS 25 // 86 // Total of 86 LED's

define DATA_PIN D6 // Change this if you are using another type of ESP board than a WeMos D1 Mini

define MILLI_AMPS 1000 //2400

CRGB LEDs[NUM_LEDS];

define NUM_CLRS 5

uint32_t color[] = {CRGB::Red, CRGB::Green, CRGB::Blue, CRGB::Orange, CRGB::White};

// Settings byte brightness = 1; // 0 to 255 CRGB alternateColor = CRGB::Black;

/* For this sketch, the segments are ordered as so. 3 WS2812 LED's per segment in SEQUENTIAL ORDER - wjb

// Each of these long's are 21 bits long. 3 LED's per segment times 7 segments = 21 // They also are written backwards, meaning the 1st segment is the last 3 bits in the long. // Looking at the ZERO will confirm this, with seg 7, the center segment, being all zeros //long numbers[] = { // 0b000111111111111111111, // [0] 0 // 0b000111000000000000111, // [1] 1 // 0b111111111000111111000, // [2] 2 // 0b111111111000000111111, // [3] 3 // 0b111111000111000000111, // [4] 4 // 0b111000111111000111111, // [5] 5 // 0b111000111111111111111, // [6] 6 // 0b000111111000000000111, // [7] 7 // 0b111111111111111111111, // [8] 8 // 0b111111111111000111111, // [9] 9 // 0b000000000000000000000, // [10] off // 0b111111111111000000000, // [11] degrees symbol // 0b000000111111111111000, // [12] C(elsius) // 0b111000111111111000000, // [13] F(ahrenheit) //};

// I built this array for the numbers 0 to 9, using 25 bit longs, for the 5X5 matrix arrays I bought off Aliexpress - wjb // 2222221111111111 // 5432109876543210987654321 long numbers[] = { 0b0000011111100011000111111, // [0] 0 0b0000000001111111000100000, // [1] 1 0b0000011101101011010111101, // [2] 2 0b0000011111101011010110101, // [3] 3 0b0000011111001000010000111, // [4] 4 0b0000010111101011010110111, // [5] 5 0b0000000111101001010111111, // [6] 6 0b0000011111000011000000011, // [7] 7 0b0000011111101011010111111, // [0] 8 0b0000011111001011010000111 // [9] 9 };

int td = 1000; // time delay

void setup() { Serial.begin(115200); Serial.println(); Serial.println(); Serial.println(FILE); // show sketch name in the Serial Monitor.

FastLED.addLeds<WS2812B, DATA_PIN, GRB>(LEDs, NUM_LEDS); // GRB order on the LED's is typical for WS2812B LED's FastLED.setDither(false); FastLED.setCorrection(TypicalLEDStrip); FastLED.setMaxPowerInVoltsAndMilliamps(5, MILLI_AMPS); fill_solid(LEDs, NUM_LEDS, CRGB::Black); // turn off all LED's FastLED.show(); }

void loop() {

// loop thru all the numbers defined in the array for (int i = 0; i <= 9; i++) {

// generate a random color from those in the array
byte clr = random(0,NUM_CLRS);
Serial.print("Random color index: ");  Serial.print(clr); Serial.print(", color number: ");  Serial.println(color[clr]);

// generate a random number between 0 and 9, to display
//byte num = random(0,4);
//displayNumber(num, 0, color[clr]);
//displayNumber(num, 0, CRGB::Red);
//Serial.print("Random number to display: "); Serial.println(num);

CRGB colr = CRGB(255, 255, 255); // <<<<<<<<<<<<< CHANGE COLOR HERE TO SOMETHING W/O RED

displayNumber(i, 0, colr);
FastLED.setBrightness(brightness);
FastLED.show();
delay(td);
fill_solid(LEDs, NUM_LEDS, CRGB::Black); // turn off all LED's
FastLED.show();

} }

void displayNumber(byte number, byte segment, CRGB color) { /*

billbrach commented 3 months ago

FOUND THE PROBLEM !! Something in these 3 lines screws things up. I commented them out and it works correctly.

FastLED.setDither(false); FastLED.setCorrection(TypicalLEDStrip); FastLED.setMaxPowerInVoltsAndMilliamps(5, MILLI_AMPS);

Please CLOSE this issue.