I am trying to build a 24 display with 4 zones as below
[Clock - 4 units] [Temperature / Humid - 4 units - Alternate]
[Date / Day - 8 units - Alternate]
[ Scroll Message - 8 units]
Can anyone help me correct the code for the multi zone display. I need the logic for the four zone update with out interrupting each other.
Any suggestions are welcome.
void setup(void)
{
Serial.begin(115200);
Serial3.begin(115200); // Bluetooth communication
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LDRPin, INPUT); // For LDR
P.begin(MAX_ZONES);
P.setIntensity(0); //Set the display intensity
P.setZone(0, 0, MAX_DEVICES - 17);
P.setZone(1, MAX_DEVICES - 16, MAX_DEVICES - 9);
P.setZone(2, MAX_DEVICES - 8, MAX_DEVICES - 5);
P.setZone(3, MAX_DEVICES - 4, MAX_DEVICES - 1);
P.setFont(3, numeric7Seg);
P.setFont(2, numeric7Seg);
rotaryswitch.begin();
//***** Interrupt Service Routine for Rotary encoder inputs.
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT4) | (1 << PCINT5);
sei();
//Display routine
//P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
//P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_FADE);
//P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
P.displayZoneText(0, szMesg, PA_CENTER, frameDelay, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
P.displayZoneText(1, szDate, PA_CENTER, 0, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
P.displayZoneText(2, szTemp, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(3, szTime, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
#if USE_12H
RTC.control(DS3231_CLOCK_HALT, DS3231_OFF);
RTC.control(DS3231_12H, DS3231_ON); // DS3231_ON is for 12H
#endif
#if !USE_12H
RTC.control(DS3231_CLOCK_HALT, DS3231_OFF);
RTC.control(DS3231_12H, DS3231_OFF); // DS3231_ON is for 12H
#endif
//pinMode(ROTARY_BUTTON, INPUT_PULLUP); // KY-040 rotary does not have internal pullup resistor hence use Arduino pullup resistor.
getTime(szTime);
beep(1, SysFreq); // Buzzer to indicate the system is started
//digitalWrite(ENABLE_DISPLAY, HIGH);
//Serial.println ("Setup ends");
}
//Setup ends
//Loop
void loop(void)
{
static uint32_t lastTime = 0; // millis() memory
static uint8_t display = 0; // current display mode
//static uint8_t Temp.display = 0;
static bool flasher = false; // seconds passing flasher
doUI();
P.displayAnimate();
P.getZoneStatus(2);
// P.setTextEffect(2, PA_NO_EFFECT, PA_DISSOLVE);
if (DHT11.read(DHT11_PIN) == 0)
{
dtostrf(DHT11.temperature, 3, 0, szTemp);
//strcat(szTemp, "°");
strcat(szTemp, "°");
Serial.println("szTemp1");
}
P.displayReset(2);
//strcpy(szTemp, "");
P.displayAnimate();
P.getZoneStatus(2);
{
//P.setTextEffect(2, PA_DISSOLVE, PA_NO_EFFECT);
if (DHT11.read(DHT11_PIN) == 0)
{
dtostrf(DHT11.humidity, 3, 0, szTemp);
strcat(szMesg, "%");
Serial.println("szTemp2");
}
P.displayReset(2);
}
//strcpy(szTemp, "");
P.displayAnimate();
P.getZoneStatus(1);
{
//P.setTextEffect(1, PA_OPENING, PA_NO_EFFECT);
dow2str(RTC.dow, szDate, 18);
Serial.println("szDate1");
P.displayReset(1);
}
//strcpy(szDate, "");
P.displayAnimate();
P.getZoneStatus(1);
{
//P.setTextEffect(1, PA_OPENING, PA_NO_EFFECT);
getDate(szDate);
Serial.println("szDate2");
P.displayReset(1);
}
//strcpy(szDate, "");
P.displayAnimate();
P.getZoneStatus(0);
{
//P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
if (FIRSTRUN && count <= 9)
{
//P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
//display = 0;
strcpy(szMesg, curMessage);
strcpy_P(curMessage, (char*)pgm_read_word(&(string_table[count]))); // Necessary casts and dereferencing, just copy.
//Serial.println(curMessage);
//Serial.println (count);
//Serial.println(FIRSTRUN);
count++;
strcpy(szMesg, "");
Serial.println("szMesg");
}
//strcpy(szMesg, "");
else
{
count = 0;
strcpy(szMesg, "");
}
//strcpy(szMesg, "");
if (!FIRSTRUN)
//P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
//display = 0;
strcpy(szMesg, curMessage);
P.displayReset(0);
}
P.displayReset();
// Read and process serial input received data if available.
while (Serial3.available())
{
serialMessage[putIndex] = (char)Serial3.read();
if ((serialMessage[putIndex] == '\n') || (putIndex >= MAX_MESG - 2)) // end of message character or full buffer
{
// put in a message separator and end the string
serialMessage[putIndex] = '\0';
// restart the index for next filling spree and flag we have a message waiting
putIndex = 0;
strcpy (curMessage, serialMessage);
FIRSTRUN = false;
}
else
{
// Just save the next char in next location
serialMessage[putIndex++];
}
//FIRSTRUN = false;
}
// Finally, adjust the time string if we have to
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getTime(szTime, flasher);
flasher = !flasher;
P.displayReset(3);
}