ESP32 I2S Call used. Seconds jumps sometimes. Not glitches or wrong color

This commit is contained in:
coelner 2020-12-27 14:35:16 +01:00
parent d21301a1e8
commit 1f27ce7fa0

View File

@ -44,7 +44,8 @@ RgbwColor temp;
#define MINIMAL_BRIGHTNESS 20 #define MINIMAL_BRIGHTNESS 20
#define LDR_SCALE 16 #define LDR_SCALE 16
#define colorSaturation 192 #define colorSaturation 192
NeoPixelBrightnessBus<NeoGrbFeature, Neo800KbpsMethod> strip(NUM_LEDS, DATA_PIN); //NeoPixelBrightnessBus<NeoGrbFeature, Neo800KbpsMethod> strip(NUM_LEDS, DATA_PIN);
NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1800KbpsMethod> strip(NUM_LEDS, DATA_PIN);
RgbColor red(colorSaturation, 0, 0); RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0); RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation); RgbColor blue(0, 0, colorSaturation);
@ -239,7 +240,7 @@ void syncNTP() {
} }
void setup() { void setup() {
//interrupt for one second@80Mhz! //interrupt for one second
timer = timerBegin(0, 80, true); timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true); timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 1000000, true); timerAlarmWrite(timer, 1000000, true);
@ -250,9 +251,9 @@ void setup() {
Serial.begin(SERIAL_BAUD); Serial.begin(SERIAL_BAUD);
Serial.flush(); Serial.flush();
Serial.print("CPU Frequency is: "); Serial.print("\nCPU Frequency is: ");
Serial.print(getCpuFrequencyMhz()); //Get CPU clock Serial.print(getCpuFrequencyMhz()); //Get CPU clock
Serial.print(" Mhz"); Serial.println(" Mhz");
strip.Begin(); strip.Begin();
strip.SetBrightness( MINIMAL_BRIGHTNESS ); strip.SetBrightness( MINIMAL_BRIGHTNESS );
@ -276,8 +277,10 @@ void loop()
{ {
// -- doLoop should be called as frequently as possible. // -- doLoop should be called as frequently as possible.
iotWebConf.doLoop(); iotWebConf.doLoop();
/*
while (Serial.available()) while (Serial.available())
Serial.read(); Serial.read();
*/
if (!setupDone && interruptCounter > 0) { if (!setupDone && interruptCounter > 0) {
if (currentSec < 0) { if (currentSec < 0) {
currentSec = 59; currentSec = 59;
@ -293,9 +296,7 @@ void loop()
currentSec--; currentSec--;
portEXIT_CRITICAL(&timerMux); portEXIT_CRITICAL(&timerMux);
} }
if (setupDone && interruptCounter > 0) {
while (setupDone && interruptCounter > 0) {
//brigthness measurement //brigthness measurement
ldrValue = (ldrValue + analogRead(LDR_PIN)); ldrValue = (ldrValue + analogRead(LDR_PIN));
//Serial.println(ldrValue); //Serial.println(ldrValue);