     } // end switch
 
     last_state = state;
-}
-/*************************************/
-/*   Processing depending of state   */
-/*************************************/
+  }
+  /*************************************/
+  /*   Processing depending of state   */
+  /*************************************/
 #ifndef TVOUT_SCREENS
-if (state == STATE_SCREEN_SAVER || state == STATE_SCREEN_SAVER_LITE) {
+  if (state == STATE_SCREEN_SAVER || state == STATE_SCREEN_SAVER_LITE) {
 
 
 #ifdef USE_DIVERSITY

    drawScreen.updateBandScanMode((state == STATE_RSSI_SETUP), channel, rssi, bestChannelName, bestChannelFrequency, rssi_setup_min_a, rssi_setup_max_a);

    // next channel
    if (channel < CHANNEL_MAX)    {
        channel++;
    }
    else    {
        channel = CHANNEL_MIN;
        if (state == STATE_RSSI_SETUP)      {
            if (!rssi_setup_run--)        {
                // setup done
                rssi_min_a = rssi_setup_min_a;
                rssi_max_a = rssi_setup_max_a;
                if (rssi_max_a < 125) { // user probably did not turn on the VTX during calibration
                    rssi_max_a = RSSI_MAX_VAL;
                }
                // save 16 bit
                EEPROM.write(EEPROM_ADR_RSSI_MIN_A_L, (rssi_min_a & 0xff));
                EEPROM.write(EEPROM_ADR_RSSI_MIN_A_H, (rssi_min_a >> 8));
                // save 16 bit
                EEPROM.write(EEPROM_ADR_RSSI_MAX_A_L, (rssi_max_a & 0xff));
                EEPROM.write(EEPROM_ADR_RSSI_MAX_A_H, (rssi_max_a >> 8));

#ifdef USE_DIVERSITY

                if (isDiversity()) { // only calibrate RSSI B when diversity is detected.
                    rssi_min_b = rssi_setup_min_b;
                    rssi_max_b = rssi_setup_max_b;
                    if (rssi_max_b < 125) { // user probably did not turn on the VTX during calibration
                        rssi_max_b = RSSI_MAX_VAL;
                    }
                    // save 16 bit
                    EEPROM.write(EEPROM_ADR_RSSI_MIN_B_L, (rssi_min_b & 0xff));
                    EEPROM.write(EEPROM_ADR_RSSI_MIN_B_H, (rssi_min_b >> 8));
                    // save 16 bit
                    EEPROM.write(EEPROM_ADR_RSSI_MAX_B_L, (rssi_max_b & 0xff));
                    EEPROM.write(EEPROM_ADR_RSSI_MAX_B_H, (rssi_max_b >> 8));
                }
#endif
                state = EEPROM.read(EEPROM_ADR_STATE);
                beep(1000);
            }
        }
    }
    // new scan possible by press scan
    FS_BUTTON_DIR = FSButtonDirection();
    if (digitalRead(buttonUp) == LOW ||  FS_BUTTON_DIR == 1) // force new full new scan    {
        beep(50); // beep & debounce
    delay(KEY_DEBOUNCE); // debounce
    last_state = 255; // force redraw by fake state change ;-)
    channel = CHANNEL_MIN;
    scan_start = 1;
    rssi_best = 0;
    FS_BUTTON_DIR = 0;

}
// update index after channel change
channelIndex = pgm_read_byte_near(channelList + channel);
}

/****************************/
/*      SETUP_MENU   */
/****************************/
if (state == STATE_SETUP_MENU)  {
    // simple menu
    char menu_id = 0;
    in_menu = 1;


void beep(uint16_t time)
{
  digitalWrite(led, HIGH);
  if (settings_beeps) {
    digitalWrite(buzzer, LOW); // activate beep
  }
  delay(time / 2);
  digitalWrite(led, LOW);
  digitalWrite(buzzer, HIGH);
}

uint8_t channel_from_index(uint8_t channelIndex)
{
  uint8_t loop = 0;
  uint8_t channel = 0;
  for (loop = 0; loop <= CHANNEL_MAX; loop++)
  {
    if (pgm_read_byte_near(channelList + loop) == channelIndex)
    {
      channel = loop;
      break;
    }
  }
  return (channel);
}

void wait_rssi_ready()
{
  time_screen_saver2 = millis();
  // CHECK FOR MINIMUM DELAY
  // check if RSSI is stable after tune by checking the time
  uint16_t tune_time = millis() - time_of_tune;
  if (tune_time < MIN_TUNE_TIME)
  {
    // wait until tune time is full filled
    delay(MIN_TUNE_TIME - tune_time);
  }
}
//char * toArray(int number)
//    {
