Open arifainchtein opened 1 year ago
Hi. Appearently, the ... display.showNumberDec() ... is stealing several ticks of the millis() and micros(). You will even get random millis() when you put a delay(10) behind the display.showNumberDec().
My application is to measure PWM and display but it's always random. I think I need to change to a different library. Cheers ;-)
Hello, I have made a custom board that has 6 tm1637 displays connected to an esp32.
The board uses the same pin for CLK for all displays and a unique pin for each display's DAT pin I have verified that the board works ok because the following code executes correctly:
include
include
include
uint8_t counter=0; // The amount of time (in milliseconds) between tests
define TEST_DELAY 2000
const uint8_t SEG_DONE[] = { SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O SEG_C | SEG_E | SEG_G, // n SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E };
define UI_CLK 33
define UI2_DAT 25
define UI3_DAT 26
define UI4_DAT 5
define UI5_DAT 18
define UI6_DAT 23
define UI7_DAT 32
TM1637Display display1(UI_CLK, UI2_DAT); TM1637Display display2(UI_CLK, UI5_DAT); TM1637Display display3(UI_CLK, UI3_DAT); TM1637Display display4(UI_CLK, UI6_DAT); TM1637Display display5(UI_CLK, UI4_DAT); TM1637Display display6(UI_CLK, UI7_DAT);
long lastUpdateTime=0; long lastUpdateLed=0;
define LED_PIN 19
define NUM_LEDS 8
CRGB leds[NUM_LEDS];
define MODE_PIN 34
int modePinState=1; void setup() { Serial.begin(9600); Serial.println("h"); FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); for(int i=0;i<8;i++){ leds[i] = CRGB(255, 255, 0); } FastLED.show(); pinMode(MODE_PIN, INPUT); digitalWrite(MODE_PIN, HIGH);
display1.setBrightness(0x0f); display2.setBrightness(0x0f); display3.setBrightness(0x0f); display4.setBrightness(0x0f); display5.setBrightness(0x0f); display6.setBrightness(0x0f);
display1.showNumberDec(0, false); display2.showNumberDec(0, false); display3.showNumberDec(0, false); display4.showNumberDec(9999, false); display5.showNumberDec(9999, false); display6.showNumberDec(9999, false); }
void loop() { long now = millis(); if(now-lastUpdateTime>999){ lastUpdateTime=now; display1.showNumberDec(counter, false); counter++; }else{ lastUpdateTime=0; int n2=counter+300; display2.showNumberDec(n2, false); int n3=counter+3000; display3.showNumberDec(n3, false); int n4=counter+5300; display4.showNumberDec(n4, false); display5.showNumberDec(n2, false); display6.showNumberDec(n4, false); modePinState = digitalRead(MODE_PIN); if(modePinState==HIGH){ Serial.println("Run mode"); for(int i=0;i<8;i++){ leds[i] = CRGB(0, 255, 0); } }else{ Serial.println("Program mode"); for(int i=0;i<8;i++){ leds[i] = CRGB(255, 0, 0); } } FastLED.show(); } if(now-lastUpdateLed>255){ lastUpdateLed=now; }else{ lastUpdateLed=0; if(counter>252){ counter=0; } int c=0; if(counter<125){ c=counter2; }else{ c=(252-counter)2; } FastLED.setBrightness(c ); display3.showNumberDec(c, false); FastLED.show(); } counter++; } All the displays update rapidly.
The issue that i have is that when I try to run the real code, in the setup function I display values in display 1 through 6 and they all work fine, however once it goes into the loop function, display 4,5 and 6 stop responding, they stay stuck in the original value, but displays 1,2 and 3 do change. I have tried putting delay(100) between display 3 and 4 ,5,6 but it does not help.display 4,5,6 dont respond to clear() or setting values.
In the simple tests all the displays were changing every second without an issue while in the real code the updates are more like every 10 seconds.
Any ideas? Thanks