Shifting output results on the screen

Dear all,
I would like to compose 5 frames of results which could present the value of a variable moving from frame to frame until it disappears after the last frame. In this way it would always be possible to observe the last five events obtained from a serial exit. The event generator is an AS3935 lightning sensor coupled to a mega arduino with LCD tft. The current code shown below shows only one result that is immediately replaced by the subsequent event. In addition the information disappears immediately after appearing.
I would like to look at the screen and always see the results of the last 5 lightning bolts, which will eventually be replaced one by one in sequence as they occur during a storm.

Thanks for any help…

Cesar

  #include <UTFT.h>
  #include <URTouch.h>
  #include <I2C.h>
  #include <PWFusion_AS3935_I2C.h>

      UTFT    myGLCD(ILI9341_16,38,39,40,41); 
      URTouch  myTouch( 6, 5, 4, 3, 2);

      Defining LCD Variables

      extern uint8_t SmallFont[];
      extern uint8_t BigFont[];
      extern uint8_t SevenSegNumFont[];
      int x, y;
      char currentPage, selectedUnit;


     #define SI_PIN               19
     #define IRQ_PIN              18 
     #define AS3935_ADD           0x03     // x03 - standard PWF SEN-39001-R01 config
     #define AS3935_CAPACITANCE   64      
     // defines for general chip settings
     #define AS3935_INDOORS       0
     #define AS3935_OUTDOORS      1
     #define AS3935_DIST_DIS      0
     #define AS3935_DIST_EN       1


    // interrupt trigger global var        
    volatile int8_t AS3935_ISR_Trig = 0;
    // prototypes
    void AS3935_ISR();
    PWF_AS3935_I2C  lightning0((uint8_t)IRQ_PIN, (uint8_t)SI_PIN, (uint8_t)AS3935_ADD);
    // interrupt trigger global var        
    volatile int8_t AS3935_ISR_Trig = 0;

  void setup()
  {  
  Serial.begin(9600);
  Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001-R01");
  Serial.println("beginning boot procedure....");  
  // setup for the the I2C library: (enable pullups, set speed to 400kHz)
  I2c.begin();
  I2c.pullup(true);
  I2c.setSpeed(1); 
  delay(2);  
  lightning0.AS3935_DefInit();   // set registers to default  
  // now update sensor cal for your application and power up chip
  lightning0.AS3935_ManualCal(AS3935_CAPACITANCE, AS3935_OUTDOORS, AS3935_DIST_EN);                  
  // enable interrupt (hook IRQ pin to Arduino Uno/Mega interrupt input: 0 -> pin 2, 1 -> pin 3 )
  //attachInterrupt(0, AS3935_ISR, RISING);
  attachInterrupt(digitalPinToInterrupt(IRQ_PIN), AS3935_ISR, RISING);
  lightning0.AS3935_PrintAllRegs();
  AS3935_ISR_Trig = 0;           // clear trigger
  }


 void readStormSensors(){ 
                                        // This program only handles an AS3935 lightning sensor. It does nothing until 
                                        // an interrupt is detected on the IRQ pin.
                                        while(0 == AS3935_ISR_Trig){}
                                        delay(5);
                                        // reset interrupt flag
                                        AS3935_ISR_Trig = 0;
                                        // now get interrupt source
                                        uint8_t int_src = lightning0.AS3935_GetInterruptSrc();
                                        if(0 == int_src)
                                        {
                                        Serial.println("interrupt source result not expected");
                                        myGLCD.setColor(255,255,255);
                                        myGLCD.drawRoundRect (5, 75, 155, 100);
                                        myGLCD.setColor(255,200,0);
                                        myGLCD.setFont(BigFont);
                                        myGLCD.print("No Strike",10, 80);
                                        }
                                        else if(1 == int_src)
                                        {
                                        myGLCD.print("Strike",10, 80);
                                        uint32_t lightning_energy = lightning0.AS3935_GetStrikeEnergyRaw();  
                                        uint8_t lightning_dist_km = lightning0.AS3935_GetLightningDistKm();
                                        Serial.print("Lightning detected! Distance to strike: ");
                                        Serial.print(lightning_dist_km);
                                        Serial.println(" kilometers");
                                        Serial.print("Lightning detected! Strike energy: ");
                                        Serial.print(lightning_energy);
                                        Serial.println(" eV");

                                        myGLCD.setColor(255,255,255);
                                        myGLCD.drawRoundRect (160, 75, 310, 100);
                                        myGLCD.setColor(255,200,0);
                                        myGLCD.setFont(BigFont);
                                        myGLCD.printNumI(lightning_energy,165,80,4);
                                        myGLCD.setFont(SmallFont);
                                        myGLCD.print("eV", 250, 82);

                                        myGLCD.setColor(255,255,255);
                                        myGLCD.drawRoundRect (160, 120, 310, 145);
                                        myGLCD.setColor(255,200,0);
                                        myGLCD.setFont(BigFont);
                                        myGLCD.printNumI(lightning_dist_km,165,125,3);
                                        myGLCD.setFont(SmallFont);
                                        myGLCD.print("Km", 250, 128);
                                      
                                        }
                                        else if(2 == int_src)
                                        {
                                        Serial.println("Disturber detected");
                                        myGLCD.print("Disturb",10, 80);
                                        }
                                        else if(3 == int_src)
                                        {
                                        Serial.println("Noise level too high");
                                        myGLCD.print("Noise",10, 80);
                                        }
                                        lightning0.AS3935_PrintAllRegs(); // for debug.
                                        delay(50);
                                        }
      
                                                                               
                                        // this is irq handler for AS3935 interrupts, has to return void and take no arguments
                                        // always make code in interrupt handlers fast and short
                                        void AS3935_ISR()
                                        {
                                        AS3935_ISR_Trig = 1;
                                        }

I would: make an array of five elements. When a new value is generated move array[3] to array [4], array[2] to array[3], and so on. Then, put the new value in array[0]. Then use a for() loop to step through and display each of the array values.

At first, thank you for your help...

I understand your logic but I have not enough experience to implement this directly. How is the command to move the array. How do you write this?

Thanks again for your patience...

Cesar

array[4] = array[3];
// and so on then
array[0] = newvalue;

You have to make sure this bit of code is not executed continuously, it must be restricted to happening only once when a new value arrives. This is done by adapting IDE > file/examples/digital/state change detection to your problem. Did you follow the link I posted?

I took a look at the links you suggested. I think I'm beginning to understand a little bit more. I'm going to do some testing. However I still do not know how to define print for the arrays.

Can I simply establish for example: Serial.print (array [4]);

or: myGLCD.printNumI (array [4], 165,125.3);

for each array?

Thanks,

Cesar

Langoni: Can I simply establish for example: Serial.print (array [4]);

That's it. Once you become more comfortable with the language you can do it with loops.

Langoni: or: myGLCD.printNumI (array [4], 165,125.3);

I cannot advise on your display, others may know.

It is working,

Thank you for teaching me...

Cesar

!