WiFi Spectrum Analyzer

However, I did add a line to the drawing loops to check if the measurement has changed, and I also added that fix in the drawing algorithm (which is a really good idea) and it seems to be running slightly faster, so thanks for that.

The drawing part can be improved even more. You added the code to only redraw the line if the value was changed. That is optimization on line level. Now think about optimizing the drawing of lines on pixel level. What you really want is to redraw only the pixels that need to be changed. Sounds much harder than it is.

There are three scenario's:

Suppose the current value is 15;

  1. new value is 11 => only need to turn off 4 pixel;
  2. new value is 21 => only need to turn on 6 pixels
  3. new value is 15 => no pixels to change

The nice part of this is that this pixel level algorithm includes the optimization at line level (scenario 3).

You need an additional array holding the newSignal[], same size as signal[] and by comparing the two you know what to do. The amount of code is roughly the same as the

As I don't have your latest code I just "prototype" it, so you can get the idea:

    // READ NEW SIGNAL STRENGTHS
    for (unsigned char n=0; n<MAXCHANNEL; n++)
    {
      // Read the signal on current channel
      unsigned char s = radio.RADIO_RSSI(n);
      newSignal[n] = map (s, 0, 31, 0, Lcd_visible); 
    }

    // ADJUST DISPLAY
    for (unsigned char n = LCD_VISIBLE_X_RES; n > 0; n--)   // should be MAXCHANNEL ???
    {
      if (newSignal[n] > signal[n])     // stronger signal => more pixels on
      {
        for (byte y = signal[n]; y <= newSignal[n]; y++) setPixel(n, y, PIXEL_ON);
      } 
      else if (newSignal[n] < signal[n])   // weaker signal => less pixels
      {
        for (byte y = newSignal[n]; y <= signal[n]; y++) setPixel(n, y, PIXEL_OFF);
      } 
      // else if (newSignal[n] == signal[n]) {} // do nothing 

      // REMEMBER SIGNALS
      signal[n] = newSignal[n];
    }

The value of each signal entry is mapped upon 0..40,
In the previous algorithm every pixel is addressed once, ==> 40 * MAXCHANNEL == 40 * 84 = 3360 setpixel calls.
Assumption: strength per channel changes 10% on average ==> 10% of the pixels need to be redrawn, 3360 * 10% = 336 setPixel calls on average
Note 1: Only the first time more pixels need to be set.
Note 2: In worst case all pixels need to be redrawn.

I am very interested if this theoretical speedup is matched in practice.... Can you post the results?

Succes,
Rob

update -- redid the math