Date   
Re: Universal Case For Bitx And other Ham Radio Projects

Sunil Lakhani
 

Thanks Craig, we are trying always to bring some products for our community.

BTW  I am listing the case on ebay, shall drop info soon when its complete.

Thanks and best regards

Sunil

Re: Universal Case For Bitx And other Ham Radio Projects

Sunil Lakhani
 

Thanks Ben. I have fixed it, if still you have problem kindly let me know.

best of 73s

Sunil

Re: Universal Case For Bitx And other Ham Radio Projects

Sunil Lakhani
 

OK let me make it right. need to check site.

Re: Universal Case For Bitx And other Ham Radio Projects

Sunil Lakhani
 

Try these 2 links

https://cqbitx.blogspot.com
https://cqbitx.blogspot.in

Also check your PC clock date and time, if it is not correct then you get errors.

best regards


Re: Universal Case For Bitx And other Ham Radio Projects

Soundararajan Ra.
 

I am getting Error 404 msg when try to go to the page.

On Mon, Jun 19, 2017 at 1:02 AM, Craig Wadsworth <cwadsworth@...> wrote:
That is nice work.  The design is attractive. 


The web pages are being rebuilt.


Please let the list know when your web store is back up and running.  

73 de w9ctw


Re: Shielding plastic cases

terry hughes
 

hi

my bitx40 is in a plastic box with no screening.

i get no problems with unwanted signals but that maybe because i live in a very thinly populated area.

terry gm4dso

Re: Shielding plastic cases

Lawrence Galea
 

Further to my post, those who still want to use plastic boxes can try to glue cooking aluminium foil to the inside of the box.
However, I still recommend an aluminium or steel box for screening.
Screening is important both to prevent pick up of unwanted signals and also unwanted radiation of signals from the TX circuitry not on the intended frequency.
Regards
Lawrence

On Mon, Jun 19, 2017 at 6:36 AM, Raj vu2zap <rajendrakumargg@...> wrote:
Kevin,

I was referring to my rig service days, I remember having problems with FT747.

This type of tape comes in various widths.
http://www.ebay.com/itm/30mm-X-2M-Guitar-Pickup-COPPER-Foil-EMI-Shielding-Tape-/151314127378?hash=item233b065a12:g:lWIAAOSwt5hYYyzk

Tape lines side by side and solder the strips together.  IMHO No need to solder the whole strip but a  spot
of solder to keep them electrically connected.
Solder a wire from ground to the tape.

Considering Bitx40 which has the PCB bottom side almost a ground plane, the case shielding may not
make much difference. I have not shielded mine.

Raj

At 18/06/2017, you wrote:
>Hi Raj,
>
>Can you send me photo of how you taped your case? I just received a nice plastic case and before I go drilling and cutting I would like some information about where to run the copper tape. Also what connections need to be made. The case does have a screw on plastic top, so I am guessing I need to place some tape there as well??
>
>Any ideas you may have would be Appreciated!
>73.
>Kevin NZ1I





Re: Shielding plastic cases

 

Kevin,

I was referring to my rig service days, I remember having problems with FT747.

This type of tape comes in various widths.
http://www.ebay.com/itm/30mm-X-2M-Guitar-Pickup-COPPER-Foil-EMI-Shielding-Tape-/151314127378?hash=item233b065a12:g:lWIAAOSwt5hYYyzk

Tape lines side by side and solder the strips together. IMHO No need to solder the whole strip but a spot
of solder to keep them electrically connected.
Solder a wire from ground to the tape.

Considering Bitx40 which has the PCB bottom side almost a ground plane, the case shielding may not
make much difference. I have not shielded mine.

Raj

At 18/06/2017, you wrote:
Hi Raj,

Can you send me photo of how you taped your case? I just received a nice plastic case and before I go drilling and cutting I would like some information about where to run the copper tape. Also what connections need to be made. The case does have a screw on plastic top, so I am guessing I need to place some tape there as well??

Any ideas you may have would be Appreciated!
73.
Kevin NZ1I

Re: Shielding plastic cases

 

Please remember that the pillars on BITX40 are NOT connected to the ground. You will need to run a thin wire from ground plane to the pillar mount pcb pads.

Cheers
Raj

Re: More on troubleshooting.

 

Andy,

What was the signal levels at the input of this stage. Did you compare both boards?

Sent from my iPhone

On 19-Jun-2017, at 08:20, KM4TRT via Groups.Io <garello@...> wrote:

Hi Raj
C41  (I miscommuicated) is the cap going from the rf amp into the filter string, where I get a good signal on my friends board.
I checked all the parts that you mentioned and every thing was ok .   Took out T2 and found nothing wrong.
I probably will pull out the diodes as I don't think I can check them in their configuration. Then T1.\
I don't know how else to approach.
Andy

Re: More on troubleshooting.

Jerry Gaffke
 

Andy,

10db is a difference of about one and a half S units on receive, might not be noticed.
But is a factor of 10 down in power on your wattmeter, a bit more obvious on transmit.

You say the VFO works, are you sure?
I'd compare T2-1 and T2-6 between bad board and good board., looking with a scope.

Amp at Q4 might be presenting a funny load to the diode ring mixer.
Maybe pull C43, replace it with a 100 ohm resistor to ground, scope across that resistor
looking for 12mhz energy.

If waveforms around the diodes look symetrical, they are probably ok.


On Sun, Jun 18, 2017 at 07:50 pm, KM4TRT wrote:
C41  (I miscommuicated) is the cap going from the rf amp into the filter string, where I get a good signal on my friends board.
I checked all the parts that you mentioned and every thing was ok .   Took out T2 and found nothing wrong.
I probably will pull out the diodes as I don't think I can check them in their configuration. Then T1.\
I don't know how else to approach.

Re: BITX QSO Night, Sunday, June 18, 7pm Local Time, 7277 kHz in North America, 7177 kHz elsewhere

John Smith
 

Almost all night I heard W1LY calling CQ, but when talking to someone his audio level goes down and I can't understand anything he says. Sometimes I can hear him saying the other persons call sign, but it's when he is calling, I make him out fine. And it's rare to hear anyone else at all. I suspect his antenna height is what makes him the most heard station. I need a rich sugar momma to buy me a tower, and a radio, and an amplifier, and some health care.  73.

Re: BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Joe
 

Yes, it did change - just did not see it  
now the msg is in the correct spot and size




On Sun, Jun 18, 2017 at 11:47 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Joe:

Go to line 398 which reads:

  tft.setTextSize(defaultTextSize);
  g_identifier = 0x154;

and add the yellow line and see what happens to the message.

Jack, W8TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 7:26 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work



Jack, 

After changing:

 text size in line 302,340,376  the sw1, sw2, sw3  now look good - right place right size.
text size in line 850 was a 4 now a 3 - frequency correct size and fits perfect.

The next one is the meter size its to wide  when comparing it to your good display.  ---- looked where to change value  but could not find to make it narrower.
Your good display only goes as wide as the w in sw2.


The msg is till not in correct place - did not find a location where to force it lower



Getting closer........




Joe
VE1BWV


On Sun, Jun 18, 2017 at 1:53 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Hi Joe:

It appears that there are two issues: 1) The font size, and 2) the cursor addressing. If I recall correctly, both of those issues are determined by the Adafruit_GFX library, which the mcufriend library inherits from. Try first setting the setFont() calls to the smallest size (1) and see what it looks like. Then play around with the setCursor() calls to see how that impacts it. Only make one change at a time, recompile/upload so you can assess the impact of that one change. Let me know what you find out.

Jack. W9TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 12:36 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Jack,

Thanks for talking time off your busy schedule to look at this code.

I  liked the the PD8W display,  but it now appears more obvious the code is poorly structured and therefore a nightmare for someone like me trying to work out the issues.


I  looked at you suggested changes and they make sense - and reduce code

Unfortunately it induced other errors which I could not get around.


Hmmm,

I  am thinking if Jack is finding it difficult to read then I am in big trouble .....

I believe, its probably best to work with your code, which is supported and as you made clear,  more organized /  logical.

I have your board completed and just waiting for a mini_360 vr, the chokes and the 78L08.

My progress:

I have loaded your code and the display comes on . 
V: is hovering around 4.5 - so it appears alive
I also plugged the tft into a regular atmega2560 for testing / playing..

I am using an 2.8tft. 0x1289

Compared to the picture in your manual, I see this:


 mesg appears halfway up the screen and the bottom of the meter is about  1/2 inches from the bottom of the screen.

Any suggestions where the issue be?


Thanks Joe
VE1BWV


On Sat, Jun 17, 2017 at 11:18 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Man, that code is really hard to read. Evidently he doesn't believe in functions. Anyway, look at the code where the encode switch is read. If a switch push is sensed, the code does nothing. At least try this:


  if ( digitalRead(ROT_SW1_PIN) ) {
Serial.print("in digitalRead(), mode = ");
Serial.println(mode);
        //delay(30);
        while (digitalRead(ROT_SW1_PIN)) {
          delay(1);
        }
        mode++;
        mode %= 5;    // What the hell is the purpose of this if you only use 3 increment states???
  }


And take this code:


  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);    // Handle these differences in the function as offsets based on mode
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }

and turn it into this:

void ChangeIncrement(int mode) 
{
    char msg[9];
    int increment[] = {100, 1000, 10000};        //
        ROT_d = increment[mode];
        itoa(ROT_d, msg, DEC);
        strcat(msg, " Hz);
        Serial.println(msg);

        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println(msg);
}

and change the big switch/case above with the function call. If special formatting is needed, that can be done in the function.

Jack, W8TEE

From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Saturday, June 17, 2017 4:17 PM
Subject: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Hi All,

While waiting for some parts for another project, I came across some interesting code and have been doing some work on existing code by PD8W.
I have tried to contact him for some help but he does not appear to be available.
He developed some code to add a 2.8inch tft to the bitx40.  The display is interesting and uses a rotary with the sg5351 with an atmega2560.

I have made Progress:

The display works fine.
The Vfo dial changes the sg5351 dds
When i disconnect the current raduino board and the vfo connector on my bit40, then connect my test unit, I can tune fine, no clicks or noise , reception is great.

Problem: - push buttons?

The code uses the switch on the rotary or a standard push button to change the range step  tuning (10khz,1khz,100hz etc etc.
It uses pin 46 (atmega 2560) but I tried it on other pins as well.
I cant seem to make the button work. If i hold the wire which is connected to the pin, the range starts changing(capacitive effect I guess)  but If i try a button it does not change the step tuning.
I have tried using _pullup command - no change.
Also tried 10k pullup resistor (pin to resistor to 5v) - no change.
Tried 10k to ground - no change.
Tried direct - to pin to button - 
Also tried other push buttons to make sure they were good.

This should be simple but I am running out of ideas.

If any one can provide a solution or some ideas to try, for this one button , it will probably solve the same issues with the remaining buttons .
Any help would be much appreciated

Joe
VE1BWV

 
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSerifBold12pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <MCUFRIEND_kbv.h>
#include <Wire.h>
#include <Rotary.h>
#include <si5351.h>
 
#define  ROT_L1_PIN 49// rotary A
#define  ROT_R1_PIN 48//rotaryA
#define  LED_R_PIN 45
#define  LED_G_PIN 44
#define  LED_B_PIN 47
#define ROT_SW1_PIN 46//   <<<<<<< this is the step range tuning button >>>>>>>>>>>
#define  ROT_LEFT  1
#define  ROT_RIGHT 2
#define  ROT_STAY  3
#define ROT_MIN        700000UL               // Lower frequency limit
#define ROT_MAX        5000000000UL
#define CALLSIGN "PD8W"
#define BITX40   "BITX40 V3c"
 
int ROT_d = 10;
int mode = 0;
int oldMode = -1;
 
Si5351 si5351;
Rotary r = Rotary(ROT_L1_PIN, ROT_R1_PIN);
volatile uint32_t LSB = 1199850000ULL;
volatile uint32_t USB = 1200150000ULL;
volatile uint32_t bfo = LSB; //start in lsb
//In this sketch the start frequency will be 7.100000 Mhz
volatile uint32_t vfo = 709980000ULL / SI5351_FREQ_MULT; //start freq - change to suit
boolean changed_f = 0;
String tbfo = "";
long lastMilis = 0;       // to track the last sampled time
long val1a, val1b;
long dirRot1 = ROT_STAY;
long valRot1 = vfo;
long oldVal1 = -1;
//---------------------------- --- Set Optional Features here ------------------------------ --------
//Remove comment (//) from the option you want to use. Pick only one
#define IF_Offset //Output is the display plus or minus the bfo frequency
//#define Direct_conversion //What you see on display is what you get
//#define FreqX4  //output is four times the display frequency
//---------------------------- ------------------------------ ------------------------------ ----------
 
MCUFRIEND_kbv tft;
 
const int  buttonPin = 52;    // pins that  pushbuttons are attached  for tx/rx   mode/ etc
const int  buttonPin2 = 53;
const int  buttonPin3 = 51;
const int  buttonPin4 = 50;
const int  buttonPin5 = 43;
 
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonPushCounter2 = 0;   // counter for the number of button presses
int buttonPushCounter3 = 0;   // counter for the number of button presses
int buttonPushCounter4 = 0;   // counter for the number of button presses
int buttonPushCounter5 = 0;   // counter for the number of button presses
 
 
int buttonState = 0;         // current state of the button
int buttonState2 = 0;         // current state of the button
int buttonState3 = 0;         // current state of the button
int buttonState4 = 0;         // current state of the button
int buttonState5 = 0;         // current state of the button
 
 
int lastButtonState = 0;     // previous state of the button
int lastButtonState2 = 0;     // previous state of the button
int lastButtonState3 = 0;     // previous state of the button
int lastButtonState4 = 0;     // previous state of the button
int lastButtonState5 = 0;     // previous state of the button
 
// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x0353
#define OBLUE   0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x7BEF
#define DARKGREY 0x18E3
 
uint16_t g_identifier;
 
void setup(void) {
  Serial.begin(9600);
  pinMode(LED_R_PIN, OUTPUT);
  pinMode(LED_G_PIN, OUTPUT);
  pinMode(LED_B_PIN, OUTPUT);
  Wire.begin();
 
  si5351.set_correction(140); //**mine. There is a calibration sketch in File/Examples/si5351Arduino- Jason
  //where you can determine the correction by using the serial monitor.
 
  //initialize the Si5351
  si5351.init(SI5351_CRYSTAL_ LOAD_8PF, 0); //If you're using a 27Mhz crystal, put in 27000000 instead of 0
  // 0 is the default crystal frequency of 25Mhz.
 
  si5351.set_pll(SI5351_PLL_ FIXED, SI5351_PLLA);
  // Set CLK0 to output the starting "vfo" frequency as set above by vfo = ?
 
#ifdef IF_Offset
  uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
  si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
  // seems not used : volatile uint32_t vfoT = (vfo * SI5351_FREQ_MULT) - bfo;
  tbfo = "LSB";
  // Set CLK2 to output bfo frequency
  si5351.set_freq( bfo, 0, SI5351_CLK2);
  si5351.drive_strength(SI5351_ CLK0, SI5351_DRIVE_2MA); //you can set this to 2MA, 4MA, 6MA or 8MA
  //si5351.drive_strength( SI5351_CLK1,SI5351_DRIVE_2MA); //be careful though - measure into 50ohms
  //si5351.drive_strength( SI5351_CLK2,SI5351_DRIVE_2MA); //
#endif
 
#ifdef Direct_conversion
  si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
#ifdef FreqX4
  si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
  int i = 0;
  pinMode(ROT_L1_PIN, INPUT);
  pinMode(ROT_R1_PIN, INPUT);
  digitalWrite(ROT_L1_PIN, HIGH); //pull-up enable
  digitalWrite(ROT_R1_PIN, HIGH); //pull-up enable
 
  pinMode(ROT_SW1_PIN, INPUT); //  non pull up  <<<<<<<<<<<<<<<<<<< range step tuning  button>>>>>>>>>>>>>>>>>
 
  uint32_t when = millis();
  //    while (!Serial) ;   //hangs a Leonardo until you connect a Serial
  if (!Serial) delay(5000);           //allow some time for Leonardo
  Serial.println("Serial took " + String((millis() - when)) + "ms to start");
  static uint16_t identifier;
  //    tft.reset();                 //we can't read ID on 9341 until begin()
  g_identifier = tft.readID(); //
  Serial.print("ID = 0x");
  Serial.println(g_identifier, HEX);
  if (g_identifier == 0x00D3 || g_identifier == 0xD3D3) g_identifier = 0x9481; // write-only shield
  if (g_identifier == 0xFFFF) g_identifier = 0x9341; // serial
  //    g_identifier = 0x9329;                             // force ID
  tft.begin(g_identifier);
 
#if defined(MCUFRIEND_KBV_H_)
  uint16_t scrollbuf[320];    // my biggest screen is 320x480
#define READGRAM(x, y, buf, w, h)  tft.readGRAM(x, y, buf, w, h)
#else
  uint16_t scrollbuf[320];    // Adafruit only does 240x320
  // Adafruit can read a block by one pixel at a time
  int16_t  READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
  {
    uint16_t *p;
    for (int row = 0; row < h; row++) {
      p = block + row * w;
      for (int col = 0; col < w; col++) {
        *p++ = tft.readPixel(x + col, y + row);
      }
    }
  }
#endif
  uint8_t aspect;
  uint16_t pixel;
  char *colorname[] = {" PD8W"};
  uint16_t colormask[] = { 0x001F, 0x7BEF,  };
  uint16_t dx, rgb, n, s, wid, ht;
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  tft.drawRect(74, 58, 71, 13, GREY);
  tft.setTextSize(1);
  tft.setCursor(77, 61);
  tft.setTextColor(GREY, BLACK);
  tft.println("WB-Software");
  tft.drawRect(74, 70, 180, 100, GREY);
  tft.fillRect(75, 70, 69, 1, BLACK);
  tft.setFont();
  tft.setCursor(91, 85);
  tft.setTextColor(CYAN, BLACK);
  tft.println("Powered and developed by");
  tft.setFont(& FreeSansBold12pt7b);
  tft.setTextSize(1);
  tft.setCursor(130, 128);
  tft.setTextColor(WHITE, BLACK);
  tft.println("PD8W ");
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(118, 145);
  tft.setTextColor(YELLOW, BLACK);
  tft.println("www.pd8w.com (c)");
  tft.drawRect(183, 169, 71, 13, GREY);
  tft.fillRect(183, 169, 70, 1, BLACK);
  tft.setTextSize(1);
  tft.setCursor(186, 171);
  tft.setTextColor(GREY, BLACK);
  tft.println("version 1.0");
  delay(5000);
  tft.fillScreen(BLACK);
  tft.setFont();
  aspect = (0 + 0) & 3;
  tft.setRotation(aspect + 1);
  wid = tft.width();
  ht = tft.height();
 
  dx = wid / 32;
  for (n = 0; n < 32; n++) {
    rgb = n * 8;
    rgb = tft.color565(rgb, rgb, rgb);
    tft.fillRect(n * dx, 10, dx, 44, rgb & colormask[aspect]);
  }
  tft.setTextSize(2);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(0, 24);
  tft.print(colorname[aspect]);
  tft.setTextColor(WHITE);
  tft.print(" BITX40");
  tft.setTextSize(1);
  tft.println(" TRANSCEIVER");
  tft.setCursor(285, 25);
  tft.println("21:45");
#if defined(MCUFRIEND_KBV_H_)
  extern const uint8_t penguin[];
  tft.setAddrWindow(240, 5, 279, 59);
  tft.pushColors(penguin, 1600, 1);
#endif
  tft.setFont();
  tft.setTextSize(1);
  tft.setTextColor(GREY, BLACK);
  tft.setCursor(265, 64);
  tft.println("- 86 dBM");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(20, 125);
  tft.setTextColor(RED, BLACK);
  tft.println("VFO");
  tft.setTextSize(2);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(29, 145);
  tft.setTextColor(CYAN, BLACK);
  tft.println("A");
  tft.setTextSize(2);
  tft.setFont(& FreeSansBold12pt7b);
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(150, 155);
  tft.setTextColor(GREY, BLACK);
  tft.print("AGC-S");
  tft.setCursor(215, 155);
  tft.println("100 Hz");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(270, 145);
  tft.setTextColor(WHITE, BLACK);
  tft.println("LSB");
  tft.fillRect(20, 60, 24, 15, GREEN);
  tft.drawRect(50, 60, 24, 15, RED);
  tft.fillRect(80, 60, 28, 15, GREY);
  tft.drawRect(108, 60, 31, 15, GREY);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(20, 71);
  tft.setFont();
  tft.setTextColor(BLACK);
  tft.println(" RX ");
  tft.setCursor(50, 64);
  tft.setTextColor(RED);
  tft.println(" TX ");
  tft.setCursor(81, 64);
  tft.setTextColor(BLACK);
  tft.println(" BW ");
  tft.setCursor(107, 63);
  tft.setTextColor(GREY);
  tft.println(" 3.0k ");
  tft.drawLine(155, 72, 160, 60, WHITE);
  tft.drawLine(176, 60, 181, 72, WHITE);
  tft.fillRect(161, 60, 15, 1, WHITE);
  tft.fillRect(148, 72, 42, 1, WHITE);
  tft.fillRect(168, 68, 1, 4, WHITE);
  tft.setCursor(39, 180);
  tft.print("S");
  tft.setCursor(59, 180);
  tft.print("1");
  tft.setCursor(84, 180);
  tft.print("3");
  tft.setCursor(110, 180);
  tft.print("5");
  tft.setCursor(136, 180);
  tft.print("7");
  tft.setCursor(162, 180);
  tft.print("9");
  tft.setTextColor(RED);
  tft.setCursor(186, 180);
  tft.print("+20");
  tft.setCursor(218, 180);
  tft.print("+40");
  tft.setCursor(250, 180);
  tft.print("+60dB");
  tft.fillRect(60, 189, 2, 3, WHITE);
  tft.fillRect(73, 189, 2, 3, WHITE);
  tft.fillRect(86, 189, 2, 3, WHITE);
  tft.fillRect(99, 189, 2, 3, WHITE);
  tft.fillRect(112, 189, 2, 3, WHITE);
  tft.fillRect(125, 189, 2, 3, WHITE);
  tft.fillRect(138, 189, 2, 3, WHITE);
  tft.fillRect(151, 189, 2, 3, WHITE);
  tft.fillRect(164, 189, 2, 3, WHITE);
  tft.fillRect(196, 189, 2, 3, RED);
  tft.fillRect(228, 189, 2, 3, RED);
  tft.fillRect(260, 189, 2, 3, RED);
  for (s = 50; s < 167; s++) {
    tft.fillRect(s, 192, 1, 1, WHITE);
  }
  for (s = 167; s < 271; s++) {
    tft.fillRect(s, 191, 1, 2, RED);
  }
  for (s = 50; s < 270; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, GREY);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
    tft.fillRect(s, 203, 3, 1, WHITE);
  }
  for (i = 0; i < 1; i++) {
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 52; s <= 165; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, BLUE);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 165; s <= 270; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, RED);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    for (s = 270; s >= 168; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, RED);
      delay(2);
    }
    tft.fillRect(166, 193, 2, 10, GREY);
    tft.fillRect(165, 193, 1, 10, BLACK);
    for (s = 164; s >= 52; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, BLUE);
      delay(2);
    }
  }
  for (s = 50; s < 164; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, BLUE);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  for (s = 164; s < 181; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, RED);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  tft.fillRect(50, 193, 2, 10, WHITE);
  tft.setCursor(30, 206);
  tft.setTextColor(GREY, BLACK);
  tft.print("Po 0");
  tft.setCursor(110, 206);
  tft.print("25");
  tft.setCursor(162, 206);
  tft.print("50");
  tft.setCursor(255, 206);
  tft.print("100%");
  tft.setCursor(0, 231);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(1);
  tft.print("Version 1.0 - WB-Software (c) 2016");
  tft.print(" GPU:");
  tft.print(tft.readID(), HEX);
  tft.print("@");
  tft.print(0.000001 * F_CPU);
  tft.println("MHz");
  delay(2000);
  tft.fillRect(0, 230, 320, 10, BLACK);
  tft.fillRect(2, 225, 60, 15, DARKGREY);
  tft.drawRect(2, 225, 60, 15, GREY);
  tft.setCursor(16, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("METER");
  tft.fillRect(66, 225, 60, 15, DARKGREY);
  tft.drawRect(66, 225, 60, 15, GREY);
  tft.setCursor(75, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("VFO/MEM");
  tft.fillRect(130, 225, 60, 15, DARKGREY);
  tft.drawRect(130, 225, 60, 15, GREY);
  tft.setCursor(142, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("SSB/CW");
  tft.fillRect(194, 225, 60, 15, DARKGREY);
  tft.drawRect(194, 225, 60, 15, GREY);
  tft.setCursor(200, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("TRANSMIT");
  tft.fillRect(258, 225, 60, 15, DARKGREY);
  tft.drawRect(258, 225, 60, 15, GREY);
  tft.setCursor(271, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("FILTER");
}
 
void loop(void) {
  digitalWrite(LED_R_PIN, HIGH);
  digitalWrite(LED_G_PIN, HIGH);
  digitalWrite(LED_B_PIN, LOW);
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      buttonPushCounter++;
      switch (buttonPushCounter) {
        case 1:
          Serial.println("4.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 4.0k ");
          tft.drawLine(152, 72, 157, 60, WHITE);
          tft.drawLine(181, 60, 186, 72, WHITE);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 2:
          Serial.println("1.8k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 1.8k ");
          tft.drawLine(160, 72, 165, 60, WHITE);
          tft.drawLine(171, 60, 176, 72, WHITE);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(165, 60, 6, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 3:
          Serial.println("2.4k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 2.4k ");
          tft.drawLine(158, 72, 163, 60, WHITE);
          tft.drawLine(173, 60, 178, 72, WHITE);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.fillRect(163, 60, 10, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 4:
          Serial.println("3.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 3.0k ");
          tft.drawLine(155, 72, 160, 60, WHITE);
          tft.drawLine(176, 60, 181, 72, WHITE);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.fillRect(161, 60, 15, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          buttonPushCounter = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState2 != lastButtonState2) {
    if (buttonState2 == HIGH) {
      buttonPushCounter2++;
      switch (buttonPushCounter2) {
        case 1:
          Serial.print("TX: button ");
          Serial.println( buttonPushCounter2);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(50, 60, 24, 15, RED);
          tft.setFont();
          tft.setTextSize(1);
          tft.setCursor(50, 64);
          tft.setTextColor(WHITE);
          tft.println(" TX ");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.drawRect(20, 60, 24, 15, GREEN);
          tft.setTextColor(GREEN);
          tft.setCursor(20, 64);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(RED);
          tft.println("Transmitting");
          break;
        case 2:
          Serial.println("RX");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.fillRect(20, 60, 24, 15, GREEN);
          tft.fillRect(50, 60, 24, 15, BLACK);
          tft.drawRect(50, 60, 24, 15, RED);
          tft.setTextColor(RED);
          tft.setCursor(50, 64);
          tft.println(" TX ");
          tft.setCursor(20, 64);
          tft.setTextColor(BLACK);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(GREEN);
          tft.println("Receiving");
          delay(1000);
          tft.fillRect(18, 78, 100, 10, BLACK);
          buttonPushCounter2 = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState3 = digitalRead(buttonPin3);
  if (buttonState3 != lastButtonState3) {
    if (buttonState3 == HIGH) {
      buttonPushCounter3++;
      switch (buttonPushCounter3) {
        case 1:
          Serial.println("USB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("USB");
          break;
        case 2:
          Serial.println("CW");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("CW");
          break;
        case 3:
          Serial.println("LSB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("LSB");
          buttonPushCounter3 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState4 = digitalRead(buttonPin4);
  if (buttonState4 != lastButtonState4) {
    if (buttonState4 == HIGH) {
      buttonPushCounter4++;
      switch (buttonPushCounter4) {
        case 1:
          Serial.println("VFO B");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("B");
          break;
        case 2:
          Serial.println("MEM");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(YELLOW, BLACK);
          tft.println("MEM");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("001");
          break;
        case 3:
          Serial.println("VFO A");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 20, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("A");
          buttonPushCounter4 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState5 = digitalRead(buttonPin5);
  if (buttonState5 != lastButtonState5) {
    if (buttonState5 == HIGH) {
      buttonPushCounter5++;
      int s = 0;
      int t = 0;
      int i = 0;
      switch (buttonPushCounter5) {
        case 1:
          Serial.println("SWR");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("SWR");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(48, 206);
          tft.print("1");
          tft.setCursor(70, 206);
          tft.print("1.5");
          tft.setCursor(105, 206);
          tft.print("2");
          tft.setCursor(125, 206);
          tft.print("2.5");
          tft.setCursor(162, 206);
          tft.print("3");
          tft.drawCircle(260, 208, 3, GREY);
          tft.drawCircle(266, 208, 3, GREY);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 70; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              delay(15);
            }
            for (s = 70; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 50; s < 90; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 90; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
          }
          break;
        case 2:
          Serial.println("ALC");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("ALC");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 203, 116, 2, RED);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 166; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(5);
            }
            for (s = 166; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(5);
            }
          }
          break;
        case 3:
          Serial.println("COMP");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(23, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("COMP");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 192, 9, 12, GREY);
          tft.setTextColor(BLACK, GREY);
          tft.setCursor(52, 195);
          tft.print("0");
          tft.fillRect(88, 192, 9, 12, GREY);
          tft.setCursor(90, 195);
          tft.print("5");
          tft.fillRect(130, 192, 13, 12, GREY);
          tft.setCursor(130, 195);
          tft.print("10");
          tft.fillRect(170, 192, 13, 12, GREY);
          tft.setCursor(170, 195);
          tft.print("15");
          tft.fillRect(211, 192, 14, 12, GREY);
          tft.setCursor(212, 195);
          tft.print("20");
          tft.fillRect(256, 192, 13, 12, GREY);
          tft.setCursor(257, 195);
          tft.print("dB");
          for (i = 0; i < 3; i++) {
            for (s = 60; s <= 86; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 98; s <= 128; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 128; s >= 96; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            for (s = 86; s >= 58; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            tft.setCursor(52, 195);
            tft.print("0");
            tft.fillRect(88, 192, 9, 12, GREY);
            tft.setCursor(90, 195);
            tft.print("5");
            tft.fillRect(130, 192, 13, 12, GREY);
            tft.setCursor(130, 195);
            tft.print("10");
            tft.fillRect(170, 192, 13, 12, GREY);
            tft.setCursor(170, 195);
            tft.print("15");
            tft.fillRect(211, 192, 14, 12, GREY);
            tft.setCursor(212, 195);
            tft.print("20");
            tft.fillRect(256, 192, 13, 12, GREY);
            tft.setCursor(257, 195);
            tft.print("dB");
          }
          break;
        case 4:
          Serial.println("ID");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("ID");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.setCursor(48, 206);
          tft.print("0");
          tft.setCursor(90, 206);
          tft.print("5");
          tft.setCursor(130, 206);
          tft.print("10");
          tft.setCursor(172, 206);
          tft.print("20");
          tft.setCursor(216, 206);
          tft.print("15");
          tft.setCursor(260, 206);
          tft.print("25A");
          tft.fillCircle(58, 209, 1, GREY);
          tft.fillCircle(66, 209, 1, GREY);
          tft.fillCircle(74, 209, 1, GREY);
          tft.fillCircle(82, 209, 1, GREY);
          tft.fillCircle(100, 209, 1, GREY);
          tft.fillCircle(108, 209, 1, GREY);
          tft.fillCircle(116, 209, 1, GREY);
          tft.fillCircle(124, 209, 1, GREY);
          tft.fillCircle(144, 209, 1, GREY);
          tft.fillCircle(152, 209, 1, GREY);
          tft.fillCircle(160, 209, 1, GREY);
          tft.fillCircle(168, 209, 1, GREY);
          tft.fillCircle(187, 209, 1, GREY);
          tft.fillCircle(195, 209, 1, GREY);
          tft.fillCircle(203, 209, 1, GREY);
          tft.fillCircle(211, 209, 1, GREY);
          tft.fillCircle(231, 209, 1, GREY);
          tft.fillCircle(239, 209, 1, GREY);
          tft.fillCircle(247, 209, 1, GREY);
          tft.fillCircle(255, 209, 1, GREY);
          tft.fillRect(92, 197, 1, 5, WHITE);
          tft.fillRect(136, 197, 1, 5, WHITE);
          tft.fillRect(178, 197, 1, 5, WHITE);
          tft.fillRect(222, 197, 1, 5, WHITE);
          tft.fillRect(264, 197, 1, 5, WHITE);
          for (i = 0; i < 1; i++) {
            for (s = 50; s < 170; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
            delay(1000);
            for (s = 170; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
          }
          break;
        case 5:
          Serial.println("S/PO");
          tft.fillRect(23, 180, 260, 40, BLACK);
          tft.setFont();
          tft.setTextColor(GREY, BLACK);
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(39, 180);
          tft.print("S");
          tft.setCursor(59, 180);
          tft.print("1");
          tft.setCursor(84, 180);
          tft.print("3");
          tft.setCursor(110, 180);
          tft.print("5");
          tft.setCursor(136, 180);
          tft.print("7");
          tft.setCursor(162, 180);
          tft.print("9");
          tft.setTextColor(RED);
          tft.setCursor(186, 180);
          tft.print("+20");
          tft.setCursor(218, 180);
          tft.print("+40");
          tft.setCursor(250, 180);
          tft.print("+60dB");
          tft.fillRect(60, 189, 2, 3, WHITE);
          tft.fillRect(73, 189, 2, 3, WHITE);
          tft.fillRect(86, 189, 2, 3, WHITE);
          tft.fillRect(99, 189, 2, 3, WHITE);
          tft.fillRect(112, 189, 2, 3, WHITE);
          tft.fillRect(125, 189, 2, 3, WHITE);
          tft.fillRect(138, 189, 2, 3, WHITE);
          tft.fillRect(151, 189, 2, 3, WHITE);
          tft.fillRect(164, 189, 2, 3, WHITE);
          tft.fillRect(196, 189, 2, 3, RED);
          tft.fillRect(228, 189, 2, 3, RED);
          tft.fillRect(260, 189, 2, 3, RED);
          for (s = 50; s < 167; s++) {
            tft.fillRect(s, 193, 1, 1, WHITE);
          }
          for (s = 166; s <= 271; s++) {
            tft.fillRect(s, 192, 1, 2, RED);
          }
          for (s = 50; s < 270; s = s + 3) {
            tft.fillRect(s, 193, 2, 10, GREY);
            tft.drawRect(s + 2, 200, 1, 10, BLACK);
            tft.fillRect(s, 203, 3, 1, WHITE);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          for (i = 0; i < 1; i++) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 52; s <= 165; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, BLUE);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 165; s <= 270; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, RED);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            for (s = 270; s >= 168; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, RED);
              delay(3);
            }
            tft.fillRect(166, 193, 2, 10, GREY);
            tft.fillRect(165, 193, 1, 10, BLACK);
            for (s = 164; s >= 52; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, BLUE);
              delay(3);
            }
          }
          for (s = 50; s < 164; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, BLUE);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          for (s = 164; s < 181; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, RED);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          buttonPushCounter5 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 }
 
  lastButtonState = buttonState;
  lastButtonState2 = buttonState2;
  lastButtonState3 = buttonState3;
  lastButtonState4 = buttonState4;
  lastButtonState5 = buttonState5;
 
  val1a = digitalRead( ROT_L1_PIN );
  val1b = digitalRead( ROT_R1_PIN );
  delay(1);
 
  // Rotary Encoder 1
  if ( val1a == HIGH && val1b == HIGH ) {
    if ( dirRot1 == ROT_LEFT ) {
      vfo += ROT_d;
      if (vfo > ROT_MAX) {
        vfo = ROT_MAX;
      }
    } else if ( dirRot1 == ROT_RIGHT ) {
      vfo -= ROT_d;
      if (vfo < ROT_MIN) {
        vfo = ROT_MIN;
      }
    }
    dirRot1 = ROT_STAY;
  } else {
    if ( val1a == LOW ) {
      dirRot1 = ROT_LEFT;
    }
    if ( val1b == HIGH ) {
      dirRot1 = ROT_RIGHT;
    }
  }
 
  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }
 
  if (oldVal1 != vfo) {
    oldVal1 = vfo;
    tft.fillRect(68, 110, 190, 40, BLACK);
    tft.fillRect(92, 145, 3, 3, WHITE);
    tft.fillRect(176, 145, 3, 3, WHITE);
    tft.setTextSize(2);
    tft.setFont(& FreeSansBold12pt7b);
    tft.setCursor(70, 145);
    tft.setTextColor(WHITE, BLACK);
    tft.println(oldVal1 + 200);
    // Serial.println(vfo);
#ifdef IF_Offset
    uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
    si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
    //you can also subtract the bfo to suit your needs
    //si5351.set_freq((vfo * SI5351_FREQ_MULT) + bfo  , SI5351_PLL_FIXED, SI5351_CLK0);
    //
    //    Serial.print("bfo : "); Serial.println(bfo);
    //    Serial.print("vfo : "); Serial.println(vfo);
    //    Serial.print("mult : "); Serial.println(int(SI5351_ FREQ_MULT));
    //    Serial.print("vco : "); Serial.println(vco);
    if (vfo >= 10000000ULL & tbfo != "USB")
    {
      bfo = USB;
      tbfo = "USB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from LSB to USB");
    }
    else if (vfo < 10000000ULL & tbfo != "LSB")
    {
      bfo = LSB;
      tbfo = "LSB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from USB to LSB");
    }
#endif
 
#ifdef Direct_conversion
    si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
 
#ifdef FreqX4
    si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
    delay(30);
  }
// DIGITAL STEP TUNING - SW1

  if ( digitalRead(ROT_SW1_PIN) ) {
    //delay(30);
    while (digitalRead(ROT_SW1_PIN)) {
      delay(1);
    }
    mode++;
    mode %= 5;
  }
}
 



Virus-free. www.avast.com







Re: BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Jack Purdum <econjack@...>
 

I'm pooped...heading to bed, but will think some more on it.

Jack, W8TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 11:02 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Added the line - recompiled and uploaded - no change

On Sun, Jun 18, 2017 at 11:47 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Joe:

Go to line 398 which reads:

  tft.setTextSize( defaultTextSize);
  g_identifier = 0x154;

and add the yellow line and see what happens to the message.

Jack, W8TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 7:26 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work



Jack, 

After changing:

 text size in line 302,340,376  the sw1, sw2, sw3  now look good - right place right size.
text size in line 850 was a 4 now a 3 - frequency correct size and fits perfect.

The next one is the meter size its to wide  when comparing it to your good display.  ---- looked where to change value  but could not find to make it narrower.
Your good display only goes as wide as the w in sw2.


The msg is till not in correct place - did not find a location where to force it lower



Getting closer........




Joe
VE1BWV


On Sun, Jun 18, 2017 at 1:53 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Hi Joe:

It appears that there are two issues: 1) The font size, and 2) the cursor addressing. If I recall correctly, both of those issues are determined by the Adafruit_GFX library, which the mcufriend library inherits from. Try first setting the setFont() calls to the smallest size (1) and see what it looks like. Then play around with the setCursor() calls to see how that impacts it. Only make one change at a time, recompile/upload so you can assess the impact of that one change. Let me know what you find out.

Jack. W9TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 12:36 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Jack,

Thanks for talking time off your busy schedule to look at this code.

I  liked the the PD8W display,  but it now appears more obvious the code is poorly structured and therefore a nightmare for someone like me trying to work out the issues.


I  looked at you suggested changes and they make sense - and reduce code

Unfortunately it induced other errors which I could not get around.


Hmmm,

I  am thinking if Jack is finding it difficult to read then I am in big trouble .....

I believe, its probably best to work with your code, which is supported and as you made clear,  more organized /  logical.

I have your board completed and just waiting for a mini_360 vr, the chokes and the 78L08.

My progress:

I have loaded your code and the display comes on . 
V: is hovering around 4.5 - so it appears alive
I also plugged the tft into a regular atmega2560 for testing / playing..

I am using an 2.8tft. 0x1289

Compared to the picture in your manual, I see this:


 mesg appears halfway up the screen and the bottom of the meter is about  1/2 inches from the bottom of the screen.

Any suggestions where the issue be?


Thanks Joe
VE1BWV


On Sat, Jun 17, 2017 at 11:18 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Man, that code is really hard to read. Evidently he doesn't believe in functions. Anyway, look at the code where the encode switch is read. If a switch push is sensed, the code does nothing. At least try this:


  if ( digitalRead(ROT_SW1_PIN) ) {
Serial.print("in digitalRead(), mode = ");
Serial.println(mode);
        //delay(30);
        while (digitalRead(ROT_SW1_PIN)) {
          delay(1);
        }
        mode++;
        mode %= 5;    // What the hell is the purpose of this if you only use 3 increment states???
  }


And take this code:


  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);    // Handle these differences in the function as offsets based on mode
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }

and turn it into this:

void ChangeIncrement(int mode) 
{
    char msg[9];
    int increment[] = {100, 1000, 10000};        //
        ROT_d = increment[mode];
        itoa(ROT_d, msg, DEC);
        strcat(msg, " Hz);
        Serial.println(msg);

        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println(msg);
}

and change the big switch/case above with the function call. If special formatting is needed, that can be done in the function.

Jack, W8TEE

From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Saturday, June 17, 2017 4:17 PM
Subject: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Hi All,

While waiting for some parts for another project, I came across some interesting code and have been doing some work on existing code by PD8W.
I have tried to contact him for some help but he does not appear to be available.
He developed some code to add a 2.8inch tft to the bitx40.  The display is interesting and uses a rotary with the sg5351 with an atmega2560.

I have made Progress:

The display works fine.
The Vfo dial changes the sg5351 dds
When i disconnect the current raduino board and the vfo connector on my bit40, then connect my test unit, I can tune fine, no clicks or noise , reception is great.

Problem: - push buttons?

The code uses the switch on the rotary or a standard push button to change the range step  tuning (10khz,1khz,100hz etc etc.
It uses pin 46 (atmega 2560) but I tried it on other pins as well.
I cant seem to make the button work. If i hold the wire which is connected to the pin, the range starts changing(capacitive effect I guess)  but If i try a button it does not change the step tuning.
I have tried using _pullup command - no change.
Also tried 10k pullup resistor (pin to resistor to 5v) - no change.
Tried 10k to ground - no change.
Tried direct - to pin to button - 
Also tried other push buttons to make sure they were good.

This should be simple but I am running out of ideas.

If any one can provide a solution or some ideas to try, for this one button , it will probably solve the same issues with the remaining buttons .
Any help would be much appreciated

Joe
VE1BWV

 
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSerifBold12pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <MCUFRIEND_kbv.h>
#include <Wire.h>
#include <Rotary.h>
#include <si5351.h>
 
#define  ROT_L1_PIN 49// rotary A
#define  ROT_R1_PIN 48//rotaryA
#define  LED_R_PIN 45
#define  LED_G_PIN 44
#define  LED_B_PIN 47
#define ROT_SW1_PIN 46//   <<<<<<< this is the step range tuning button >>>>>>>>>>>
#define  ROT_LEFT  1
#define  ROT_RIGHT 2
#define  ROT_STAY  3
#define ROT_MIN        700000UL               // Lower frequency limit
#define ROT_MAX        5000000000UL
#define CALLSIGN "PD8W"
#define BITX40   "BITX40 V3c"
 
int ROT_d = 10;
int mode = 0;
int oldMode = -1;
 
Si5351 si5351;
Rotary r = Rotary(ROT_L1_PIN, ROT_R1_PIN);
volatile uint32_t LSB = 1199850000ULL;
volatile uint32_t USB = 1200150000ULL;
volatile uint32_t bfo = LSB; //start in lsb
//In this sketch the start frequency will be 7.100000 Mhz
volatile uint32_t vfo = 709980000ULL / SI5351_FREQ_MULT; //start freq - change to suit
boolean changed_f = 0;
String tbfo = "";
long lastMilis = 0;       // to track the last sampled time
long val1a, val1b;
long dirRot1 = ROT_STAY;
long valRot1 = vfo;
long oldVal1 = -1;
//---------------------------- --- Set Optional Features here ------------------------------ --------
//Remove comment (//) from the option you want to use. Pick only one
#define IF_Offset //Output is the display plus or minus the bfo frequency
//#define Direct_conversion //What you see on display is what you get
//#define FreqX4  //output is four times the display frequency
//---------------------------- ------------------------------ ------------------------------ ----------
 
MCUFRIEND_kbv tft;
 
const int  buttonPin = 52;    // pins that  pushbuttons are attached  for tx/rx   mode/ etc
const int  buttonPin2 = 53;
const int  buttonPin3 = 51;
const int  buttonPin4 = 50;
const int  buttonPin5 = 43;
 
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonPushCounter2 = 0;   // counter for the number of button presses
int buttonPushCounter3 = 0;   // counter for the number of button presses
int buttonPushCounter4 = 0;   // counter for the number of button presses
int buttonPushCounter5 = 0;   // counter for the number of button presses
 
 
int buttonState = 0;         // current state of the button
int buttonState2 = 0;         // current state of the button
int buttonState3 = 0;         // current state of the button
int buttonState4 = 0;         // current state of the button
int buttonState5 = 0;         // current state of the button
 
 
int lastButtonState = 0;     // previous state of the button
int lastButtonState2 = 0;     // previous state of the button
int lastButtonState3 = 0;     // previous state of the button
int lastButtonState4 = 0;     // previous state of the button
int lastButtonState5 = 0;     // previous state of the button
 
// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x0353
#define OBLUE   0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x7BEF
#define DARKGREY 0x18E3
 
uint16_t g_identifier;
 
void setup(void) {
  Serial.begin(9600);
  pinMode(LED_R_PIN, OUTPUT);
  pinMode(LED_G_PIN, OUTPUT);
  pinMode(LED_B_PIN, OUTPUT);
  Wire.begin();
 
  si5351.set_correction(140); //**mine. There is a calibration sketch in File/Examples/si5351Arduino- Jason
  //where you can determine the correction by using the serial monitor.
 
  //initialize the Si5351
  si5351.init(SI5351_CRYSTAL_ LOAD_8PF, 0); //If you're using a 27Mhz crystal, put in 27000000 instead of 0
  // 0 is the default crystal frequency of 25Mhz.
 
  si5351.set_pll(SI5351_PLL_ FIXED, SI5351_PLLA);
  // Set CLK0 to output the starting "vfo" frequency as set above by vfo = ?
 
#ifdef IF_Offset
  uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
  si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
  // seems not used : volatile uint32_t vfoT = (vfo * SI5351_FREQ_MULT) - bfo;
  tbfo = "LSB";
  // Set CLK2 to output bfo frequency
  si5351.set_freq( bfo, 0, SI5351_CLK2);
  si5351.drive_strength(SI5351_ CLK0, SI5351_DRIVE_2MA); //you can set this to 2MA, 4MA, 6MA or 8MA
  //si5351.drive_strength( SI5351_CLK1,SI5351_DRIVE_2MA); //be careful though - measure into 50ohms
  //si5351.drive_strength( SI5351_CLK2,SI5351_DRIVE_2MA); //
#endif
 
#ifdef Direct_conversion
  si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
#ifdef FreqX4
  si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
  int i = 0;
  pinMode(ROT_L1_PIN, INPUT);
  pinMode(ROT_R1_PIN, INPUT);
  digitalWrite(ROT_L1_PIN, HIGH); //pull-up enable
  digitalWrite(ROT_R1_PIN, HIGH); //pull-up enable
 
  pinMode(ROT_SW1_PIN, INPUT); //  non pull up  <<<<<<<<<<<<<<<<<<< range step tuning  button>>>>>>>>>>>>>>>>>
 
  uint32_t when = millis();
  //    while (!Serial) ;   //hangs a Leonardo until you connect a Serial
  if (!Serial) delay(5000);           //allow some time for Leonardo
  Serial.println("Serial took " + String((millis() - when)) + "ms to start");
  static uint16_t identifier;
  //    tft.reset();                 //we can't read ID on 9341 until begin()
  g_identifier = tft.readID(); //
  Serial.print("ID = 0x");
  Serial.println(g_identifier, HEX);
  if (g_identifier == 0x00D3 || g_identifier == 0xD3D3) g_identifier = 0x9481; // write-only shield
  if (g_identifier == 0xFFFF) g_identifier = 0x9341; // serial
  //    g_identifier = 0x9329;                             // force ID
  tft.begin(g_identifier);
 
#if defined(MCUFRIEND_KBV_H_)
  uint16_t scrollbuf[320];    // my biggest screen is 320x480
#define READGRAM(x, y, buf, w, h)  tft.readGRAM(x, y, buf, w, h)
#else
  uint16_t scrollbuf[320];    // Adafruit only does 240x320
  // Adafruit can read a block by one pixel at a time
  int16_t  READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
  {
    uint16_t *p;
    for (int row = 0; row < h; row++) {
      p = block + row * w;
      for (int col = 0; col < w; col++) {
        *p++ = tft.readPixel(x + col, y + row);
      }
    }
  }
#endif
  uint8_t aspect;
  uint16_t pixel;
  char *colorname[] = {" PD8W"};
  uint16_t colormask[] = { 0x001F, 0x7BEF,  };
  uint16_t dx, rgb, n, s, wid, ht;
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  tft.drawRect(74, 58, 71, 13, GREY);
  tft.setTextSize(1);
  tft.setCursor(77, 61);
  tft.setTextColor(GREY, BLACK);
  tft.println("WB-Software");
  tft.drawRect(74, 70, 180, 100, GREY);
  tft.fillRect(75, 70, 69, 1, BLACK);
  tft.setFont();
  tft.setCursor(91, 85);
  tft.setTextColor(CYAN, BLACK);
  tft.println("Powered and developed by");
  tft.setFont(& FreeSansBold12pt7b);
  tft.setTextSize(1);
  tft.setCursor(130, 128);
  tft.setTextColor(WHITE, BLACK);
  tft.println("PD8W ");
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(118, 145);
  tft.setTextColor(YELLOW, BLACK);
  tft.println("www.pd8w.com (c)");
  tft.drawRect(183, 169, 71, 13, GREY);
  tft.fillRect(183, 169, 70, 1, BLACK);
  tft.setTextSize(1);
  tft.setCursor(186, 171);
  tft.setTextColor(GREY, BLACK);
  tft.println("version 1.0");
  delay(5000);
  tft.fillScreen(BLACK);
  tft.setFont();
  aspect = (0 + 0) & 3;
  tft.setRotation(aspect + 1);
  wid = tft.width();
  ht = tft.height();
 
  dx = wid / 32;
  for (n = 0; n < 32; n++) {
    rgb = n * 8;
    rgb = tft.color565(rgb, rgb, rgb);
    tft.fillRect(n * dx, 10, dx, 44, rgb & colormask[aspect]);
  }
  tft.setTextSize(2);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(0, 24);
  tft.print(colorname[aspect]);
  tft.setTextColor(WHITE);
  tft.print(" BITX40");
  tft.setTextSize(1);
  tft.println(" TRANSCEIVER");
  tft.setCursor(285, 25);
  tft.println("21:45");
#if defined(MCUFRIEND_KBV_H_)
  extern const uint8_t penguin[];
  tft.setAddrWindow(240, 5, 279, 59);
  tft.pushColors(penguin, 1600, 1);
#endif
  tft.setFont();
  tft.setTextSize(1);
  tft.setTextColor(GREY, BLACK);
  tft.setCursor(265, 64);
  tft.println("- 86 dBM");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(20, 125);
  tft.setTextColor(RED, BLACK);
  tft.println("VFO");
  tft.setTextSize(2);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(29, 145);
  tft.setTextColor(CYAN, BLACK);
  tft.println("A");
  tft.setTextSize(2);
  tft.setFont(& FreeSansBold12pt7b);
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(150, 155);
  tft.setTextColor(GREY, BLACK);
  tft.print("AGC-S");
  tft.setCursor(215, 155);
  tft.println("100 Hz");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(270, 145);
  tft.setTextColor(WHITE, BLACK);
  tft.println("LSB");
  tft.fillRect(20, 60, 24, 15, GREEN);
  tft.drawRect(50, 60, 24, 15, RED);
  tft.fillRect(80, 60, 28, 15, GREY);
  tft.drawRect(108, 60, 31, 15, GREY);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(20, 71);
  tft.setFont();
  tft.setTextColor(BLACK);
  tft.println(" RX ");
  tft.setCursor(50, 64);
  tft.setTextColor(RED);
  tft.println(" TX ");
  tft.setCursor(81, 64);
  tft.setTextColor(BLACK);
  tft.println(" BW ");
  tft.setCursor(107, 63);
  tft.setTextColor(GREY);
  tft.println(" 3.0k ");
  tft.drawLine(155, 72, 160, 60, WHITE);
  tft.drawLine(176, 60, 181, 72, WHITE);
  tft.fillRect(161, 60, 15, 1, WHITE);
  tft.fillRect(148, 72, 42, 1, WHITE);
  tft.fillRect(168, 68, 1, 4, WHITE);
  tft.setCursor(39, 180);
  tft.print("S");
  tft.setCursor(59, 180);
  tft.print("1");
  tft.setCursor(84, 180);
  tft.print("3");
  tft.setCursor(110, 180);
  tft.print("5");
  tft.setCursor(136, 180);
  tft.print("7");
  tft.setCursor(162, 180);
  tft.print("9");
  tft.setTextColor(RED);
  tft.setCursor(186, 180);
  tft.print("+20");
  tft.setCursor(218, 180);
  tft.print("+40");
  tft.setCursor(250, 180);
  tft.print("+60dB");
  tft.fillRect(60, 189, 2, 3, WHITE);
  tft.fillRect(73, 189, 2, 3, WHITE);
  tft.fillRect(86, 189, 2, 3, WHITE);
  tft.fillRect(99, 189, 2, 3, WHITE);
  tft.fillRect(112, 189, 2, 3, WHITE);
  tft.fillRect(125, 189, 2, 3, WHITE);
  tft.fillRect(138, 189, 2, 3, WHITE);
  tft.fillRect(151, 189, 2, 3, WHITE);
  tft.fillRect(164, 189, 2, 3, WHITE);
  tft.fillRect(196, 189, 2, 3, RED);
  tft.fillRect(228, 189, 2, 3, RED);
  tft.fillRect(260, 189, 2, 3, RED);
  for (s = 50; s < 167; s++) {
    tft.fillRect(s, 192, 1, 1, WHITE);
  }
  for (s = 167; s < 271; s++) {
    tft.fillRect(s, 191, 1, 2, RED);
  }
  for (s = 50; s < 270; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, GREY);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
    tft.fillRect(s, 203, 3, 1, WHITE);
  }
  for (i = 0; i < 1; i++) {
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 52; s <= 165; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, BLUE);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 165; s <= 270; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, RED);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    for (s = 270; s >= 168; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, RED);
      delay(2);
    }
    tft.fillRect(166, 193, 2, 10, GREY);
    tft.fillRect(165, 193, 1, 10, BLACK);
    for (s = 164; s >= 52; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, BLUE);
      delay(2);
    }
  }
  for (s = 50; s < 164; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, BLUE);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  for (s = 164; s < 181; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, RED);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  tft.fillRect(50, 193, 2, 10, WHITE);
  tft.setCursor(30, 206);
  tft.setTextColor(GREY, BLACK);
  tft.print("Po 0");
  tft.setCursor(110, 206);
  tft.print("25");
  tft.setCursor(162, 206);
  tft.print("50");
  tft.setCursor(255, 206);
  tft.print("100%");
  tft.setCursor(0, 231);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(1);
  tft.print("Version 1.0 - WB-Software (c) 2016");
  tft.print(" GPU:");
  tft.print(tft.readID(), HEX);
  tft.print("@");
  tft.print(0.000001 * F_CPU);
  tft.println("MHz");
  delay(2000);
  tft.fillRect(0, 230, 320, 10, BLACK);
  tft.fillRect(2, 225, 60, 15, DARKGREY);
  tft.drawRect(2, 225, 60, 15, GREY);
  tft.setCursor(16, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("METER");
  tft.fillRect(66, 225, 60, 15, DARKGREY);
  tft.drawRect(66, 225, 60, 15, GREY);
  tft.setCursor(75, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("VFO/MEM");
  tft.fillRect(130, 225, 60, 15, DARKGREY);
  tft.drawRect(130, 225, 60, 15, GREY);
  tft.setCursor(142, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("SSB/CW");
  tft.fillRect(194, 225, 60, 15, DARKGREY);
  tft.drawRect(194, 225, 60, 15, GREY);
  tft.setCursor(200, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("TRANSMIT");
  tft.fillRect(258, 225, 60, 15, DARKGREY);
  tft.drawRect(258, 225, 60, 15, GREY);
  tft.setCursor(271, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("FILTER");
}
 
void loop(void) {
  digitalWrite(LED_R_PIN, HIGH);
  digitalWrite(LED_G_PIN, HIGH);
  digitalWrite(LED_B_PIN, LOW);
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      buttonPushCounter++;
      switch (buttonPushCounter) {
        case 1:
          Serial.println("4.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 4.0k ");
          tft.drawLine(152, 72, 157, 60, WHITE);
          tft.drawLine(181, 60, 186, 72, WHITE);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 2:
          Serial.println("1.8k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 1.8k ");
          tft.drawLine(160, 72, 165, 60, WHITE);
          tft.drawLine(171, 60, 176, 72, WHITE);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(165, 60, 6, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 3:
          Serial.println("2.4k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 2.4k ");
          tft.drawLine(158, 72, 163, 60, WHITE);
          tft.drawLine(173, 60, 178, 72, WHITE);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.fillRect(163, 60, 10, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 4:
          Serial.println("3.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 3.0k ");
          tft.drawLine(155, 72, 160, 60, WHITE);
          tft.drawLine(176, 60, 181, 72, WHITE);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.fillRect(161, 60, 15, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          buttonPushCounter = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState2 != lastButtonState2) {
    if (buttonState2 == HIGH) {
      buttonPushCounter2++;
      switch (buttonPushCounter2) {
        case 1:
          Serial.print("TX: button ");
          Serial.println( buttonPushCounter2);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(50, 60, 24, 15, RED);
          tft.setFont();
          tft.setTextSize(1);
          tft.setCursor(50, 64);
          tft.setTextColor(WHITE);
          tft.println(" TX ");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.drawRect(20, 60, 24, 15, GREEN);
          tft.setTextColor(GREEN);
          tft.setCursor(20, 64);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(RED);
          tft.println("Transmitting");
          break;
        case 2:
          Serial.println("RX");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.fillRect(20, 60, 24, 15, GREEN);
          tft.fillRect(50, 60, 24, 15, BLACK);
          tft.drawRect(50, 60, 24, 15, RED);
          tft.setTextColor(RED);
          tft.setCursor(50, 64);
          tft.println(" TX ");
          tft.setCursor(20, 64);
          tft.setTextColor(BLACK);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(GREEN);
          tft.println("Receiving");
          delay(1000);
          tft.fillRect(18, 78, 100, 10, BLACK);
          buttonPushCounter2 = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState3 = digitalRead(buttonPin3);
  if (buttonState3 != lastButtonState3) {
    if (buttonState3 == HIGH) {
      buttonPushCounter3++;
      switch (buttonPushCounter3) {
        case 1:
          Serial.println("USB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("USB");
          break;
        case 2:
          Serial.println("CW");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("CW");
          break;
        case 3:
          Serial.println("LSB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("LSB");
          buttonPushCounter3 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState4 = digitalRead(buttonPin4);
  if (buttonState4 != lastButtonState4) {
    if (buttonState4 == HIGH) {
      buttonPushCounter4++;
      switch (buttonPushCounter4) {
        case 1:
          Serial.println("VFO B");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("B");
          break;
        case 2:
          Serial.println("MEM");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(YELLOW, BLACK);
          tft.println("MEM");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("001");
          break;
        case 3:
          Serial.println("VFO A");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 20, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("A");
          buttonPushCounter4 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState5 = digitalRead(buttonPin5);
  if (buttonState5 != lastButtonState5) {
    if (buttonState5 == HIGH) {
      buttonPushCounter5++;
      int s = 0;
      int t = 0;
      int i = 0;
      switch (buttonPushCounter5) {
        case 1:
          Serial.println("SWR");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("SWR");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(48, 206);
          tft.print("1");
          tft.setCursor(70, 206);
          tft.print("1.5");
          tft.setCursor(105, 206);
          tft.print("2");
          tft.setCursor(125, 206);
          tft.print("2.5");
          tft.setCursor(162, 206);
          tft.print("3");
          tft.drawCircle(260, 208, 3, GREY);
          tft.drawCircle(266, 208, 3, GREY);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 70; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              delay(15);
            }
            for (s = 70; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 50; s < 90; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 90; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
          }
          break;
        case 2:
          Serial.println("ALC");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("ALC");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 203, 116, 2, RED);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 166; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(5);
            }
            for (s = 166; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(5);
            }
          }
          break;
        case 3:
          Serial.println("COMP");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(23, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("COMP");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 192, 9, 12, GREY);
          tft.setTextColor(BLACK, GREY);
          tft.setCursor(52, 195);
          tft.print("0");
          tft.fillRect(88, 192, 9, 12, GREY);
          tft.setCursor(90, 195);
          tft.print("5");
          tft.fillRect(130, 192, 13, 12, GREY);
          tft.setCursor(130, 195);
          tft.print("10");
          tft.fillRect(170, 192, 13, 12, GREY);
          tft.setCursor(170, 195);
          tft.print("15");
          tft.fillRect(211, 192, 14, 12, GREY);
          tft.setCursor(212, 195);
          tft.print("20");
          tft.fillRect(256, 192, 13, 12, GREY);
          tft.setCursor(257, 195);
          tft.print("dB");
          for (i = 0; i < 3; i++) {
            for (s = 60; s <= 86; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 98; s <= 128; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 128; s >= 96; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            for (s = 86; s >= 58; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            tft.setCursor(52, 195);
            tft.print("0");
            tft.fillRect(88, 192, 9, 12, GREY);
            tft.setCursor(90, 195);
            tft.print("5");
            tft.fillRect(130, 192, 13, 12, GREY);
            tft.setCursor(130, 195);
            tft.print("10");
            tft.fillRect(170, 192, 13, 12, GREY);
            tft.setCursor(170, 195);
            tft.print("15");
            tft.fillRect(211, 192, 14, 12, GREY);
            tft.setCursor(212, 195);
            tft.print("20");
            tft.fillRect(256, 192, 13, 12, GREY);
            tft.setCursor(257, 195);
            tft.print("dB");
          }
          break;
        case 4:
          Serial.println("ID");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("ID");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.setCursor(48, 206);
          tft.print("0");
          tft.setCursor(90, 206);
          tft.print("5");
          tft.setCursor(130, 206);
          tft.print("10");
          tft.setCursor(172, 206);
          tft.print("20");
          tft.setCursor(216, 206);
          tft.print("15");
          tft.setCursor(260, 206);
          tft.print("25A");
          tft.fillCircle(58, 209, 1, GREY);
          tft.fillCircle(66, 209, 1, GREY);
          tft.fillCircle(74, 209, 1, GREY);
          tft.fillCircle(82, 209, 1, GREY);
          tft.fillCircle(100, 209, 1, GREY);
          tft.fillCircle(108, 209, 1, GREY);
          tft.fillCircle(116, 209, 1, GREY);
          tft.fillCircle(124, 209, 1, GREY);
          tft.fillCircle(144, 209, 1, GREY);
          tft.fillCircle(152, 209, 1, GREY);
          tft.fillCircle(160, 209, 1, GREY);
          tft.fillCircle(168, 209, 1, GREY);
          tft.fillCircle(187, 209, 1, GREY);
          tft.fillCircle(195, 209, 1, GREY);
          tft.fillCircle(203, 209, 1, GREY);
          tft.fillCircle(211, 209, 1, GREY);
          tft.fillCircle(231, 209, 1, GREY);
          tft.fillCircle(239, 209, 1, GREY);
          tft.fillCircle(247, 209, 1, GREY);
          tft.fillCircle(255, 209, 1, GREY);
          tft.fillRect(92, 197, 1, 5, WHITE);
          tft.fillRect(136, 197, 1, 5, WHITE);
          tft.fillRect(178, 197, 1, 5, WHITE);
          tft.fillRect(222, 197, 1, 5, WHITE);
          tft.fillRect(264, 197, 1, 5, WHITE);
          for (i = 0; i < 1; i++) {
            for (s = 50; s < 170; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
            delay(1000);
            for (s = 170; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
          }
          break;
        case 5:
          Serial.println("S/PO");
          tft.fillRect(23, 180, 260, 40, BLACK);
          tft.setFont();
          tft.setTextColor(GREY, BLACK);
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(39, 180);
          tft.print("S");
          tft.setCursor(59, 180);
          tft.print("1");
          tft.setCursor(84, 180);
          tft.print("3");
          tft.setCursor(110, 180);
          tft.print("5");
          tft.setCursor(136, 180);
          tft.print("7");
          tft.setCursor(162, 180);
          tft.print("9");
          tft.setTextColor(RED);
          tft.setCursor(186, 180);
          tft.print("+20");
          tft.setCursor(218, 180);
          tft.print("+40");
          tft.setCursor(250, 180);
          tft.print("+60dB");
          tft.fillRect(60, 189, 2, 3, WHITE);
          tft.fillRect(73, 189, 2, 3, WHITE);
          tft.fillRect(86, 189, 2, 3, WHITE);
          tft.fillRect(99, 189, 2, 3, WHITE);
          tft.fillRect(112, 189, 2, 3, WHITE);
          tft.fillRect(125, 189, 2, 3, WHITE);
          tft.fillRect(138, 189, 2, 3, WHITE);
          tft.fillRect(151, 189, 2, 3, WHITE);
          tft.fillRect(164, 189, 2, 3, WHITE);
          tft.fillRect(196, 189, 2, 3, RED);
          tft.fillRect(228, 189, 2, 3, RED);
          tft.fillRect(260, 189, 2, 3, RED);
          for (s = 50; s < 167; s++) {
            tft.fillRect(s, 193, 1, 1, WHITE);
          }
          for (s = 166; s <= 271; s++) {
            tft.fillRect(s, 192, 1, 2, RED);
          }
          for (s = 50; s < 270; s = s + 3) {
            tft.fillRect(s, 193, 2, 10, GREY);
            tft.drawRect(s + 2, 200, 1, 10, BLACK);
            tft.fillRect(s, 203, 3, 1, WHITE);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          for (i = 0; i < 1; i++) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 52; s <= 165; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, BLUE);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 165; s <= 270; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, RED);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            for (s = 270; s >= 168; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, RED);
              delay(3);
            }
            tft.fillRect(166, 193, 2, 10, GREY);
            tft.fillRect(165, 193, 1, 10, BLACK);
            for (s = 164; s >= 52; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, BLUE);
              delay(3);
            }
          }
          for (s = 50; s < 164; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, BLUE);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          for (s = 164; s < 181; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, RED);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          buttonPushCounter5 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 }
 
  lastButtonState = buttonState;
  lastButtonState2 = buttonState2;
  lastButtonState3 = buttonState3;
  lastButtonState4 = buttonState4;
  lastButtonState5 = buttonState5;
 
  val1a = digitalRead( ROT_L1_PIN );
  val1b = digitalRead( ROT_R1_PIN );
  delay(1);
 
  // Rotary Encoder 1
  if ( val1a == HIGH && val1b == HIGH ) {
    if ( dirRot1 == ROT_LEFT ) {
      vfo += ROT_d;
      if (vfo > ROT_MAX) {
        vfo = ROT_MAX;
      }
    } else if ( dirRot1 == ROT_RIGHT ) {
      vfo -= ROT_d;
      if (vfo < ROT_MIN) {
        vfo = ROT_MIN;
      }
    }
    dirRot1 = ROT_STAY;
  } else {
    if ( val1a == LOW ) {
      dirRot1 = ROT_LEFT;
    }
    if ( val1b == HIGH ) {
      dirRot1 = ROT_RIGHT;
    }
  }
 
  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }
 
  if (oldVal1 != vfo) {
    oldVal1 = vfo;
    tft.fillRect(68, 110, 190, 40, BLACK);
    tft.fillRect(92, 145, 3, 3, WHITE);
    tft.fillRect(176, 145, 3, 3, WHITE);
    tft.setTextSize(2);
    tft.setFont(& FreeSansBold12pt7b);
    tft.setCursor(70, 145);
    tft.setTextColor(WHITE, BLACK);
    tft.println(oldVal1 + 200);
    // Serial.println(vfo);
#ifdef IF_Offset
    uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
    si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
    //you can also subtract the bfo to suit your needs
    //si5351.set_freq((vfo * SI5351_FREQ_MULT) + bfo  , SI5351_PLL_FIXED, SI5351_CLK0);
    //
    //    Serial.print("bfo : "); Serial.println(bfo);
    //    Serial.print("vfo : "); Serial.println(vfo);
    //    Serial.print("mult : "); Serial.println(int(SI5351_ FREQ_MULT));
    //    Serial.print("vco : "); Serial.println(vco);
    if (vfo >= 10000000ULL & tbfo != "USB")
    {
      bfo = USB;
      tbfo = "USB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from LSB to USB");
    }
    else if (vfo < 10000000ULL & tbfo != "LSB")
    {
      bfo = LSB;
      tbfo = "LSB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from USB to LSB");
    }
#endif
 
#ifdef Direct_conversion
    si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
 
#ifdef FreqX4
    si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
    delay(30);
  }
// DIGITAL STEP TUNING - SW1

  if ( digitalRead(ROT_SW1_PIN) ) {
    //delay(30);
    while (digitalRead(ROT_SW1_PIN)) {
      delay(1);
    }
    mode++;
    mode %= 5;
  }
}
 



Virus-free. www.avast.com









Re: BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Joe
 

Added the line - recompiled and uploaded - no change

On Sun, Jun 18, 2017 at 11:47 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Joe:

Go to line 398 which reads:

  tft.setTextSize(defaultTextSize);
  g_identifier = 0x154;

and add the yellow line and see what happens to the message.

Jack, W8TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 7:26 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work



Jack, 

After changing:

 text size in line 302,340,376  the sw1, sw2, sw3  now look good - right place right size.
text size in line 850 was a 4 now a 3 - frequency correct size and fits perfect.

The next one is the meter size its to wide  when comparing it to your good display.  ---- looked where to change value  but could not find to make it narrower.
Your good display only goes as wide as the w in sw2.


The msg is till not in correct place - did not find a location where to force it lower



Getting closer........




Joe
VE1BWV


On Sun, Jun 18, 2017 at 1:53 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Hi Joe:

It appears that there are two issues: 1) The font size, and 2) the cursor addressing. If I recall correctly, both of those issues are determined by the Adafruit_GFX library, which the mcufriend library inherits from. Try first setting the setFont() calls to the smallest size (1) and see what it looks like. Then play around with the setCursor() calls to see how that impacts it. Only make one change at a time, recompile/upload so you can assess the impact of that one change. Let me know what you find out.

Jack. W9TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 12:36 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Jack,

Thanks for talking time off your busy schedule to look at this code.

I  liked the the PD8W display,  but it now appears more obvious the code is poorly structured and therefore a nightmare for someone like me trying to work out the issues.


I  looked at you suggested changes and they make sense - and reduce code

Unfortunately it induced other errors which I could not get around.


Hmmm,

I  am thinking if Jack is finding it difficult to read then I am in big trouble .....

I believe, its probably best to work with your code, which is supported and as you made clear,  more organized /  logical.

I have your board completed and just waiting for a mini_360 vr, the chokes and the 78L08.

My progress:

I have loaded your code and the display comes on . 
V: is hovering around 4.5 - so it appears alive
I also plugged the tft into a regular atmega2560 for testing / playing..

I am using an 2.8tft. 0x1289

Compared to the picture in your manual, I see this:


 mesg appears halfway up the screen and the bottom of the meter is about  1/2 inches from the bottom of the screen.

Any suggestions where the issue be?


Thanks Joe
VE1BWV


On Sat, Jun 17, 2017 at 11:18 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Man, that code is really hard to read. Evidently he doesn't believe in functions. Anyway, look at the code where the encode switch is read. If a switch push is sensed, the code does nothing. At least try this:


  if ( digitalRead(ROT_SW1_PIN) ) {
Serial.print("in digitalRead(), mode = ");
Serial.println(mode);
        //delay(30);
        while (digitalRead(ROT_SW1_PIN)) {
          delay(1);
        }
        mode++;
        mode %= 5;    // What the hell is the purpose of this if you only use 3 increment states???
  }


And take this code:


  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);    // Handle these differences in the function as offsets based on mode
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }

and turn it into this:

void ChangeIncrement(int mode) 
{
    char msg[9];
    int increment[] = {100, 1000, 10000};        //
        ROT_d = increment[mode];
        itoa(ROT_d, msg, DEC);
        strcat(msg, " Hz);
        Serial.println(msg);

        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println(msg);
}

and change the big switch/case above with the function call. If special formatting is needed, that can be done in the function.

Jack, W8TEE

From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Saturday, June 17, 2017 4:17 PM
Subject: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Hi All,

While waiting for some parts for another project, I came across some interesting code and have been doing some work on existing code by PD8W.
I have tried to contact him for some help but he does not appear to be available.
He developed some code to add a 2.8inch tft to the bitx40.  The display is interesting and uses a rotary with the sg5351 with an atmega2560.

I have made Progress:

The display works fine.
The Vfo dial changes the sg5351 dds
When i disconnect the current raduino board and the vfo connector on my bit40, then connect my test unit, I can tune fine, no clicks or noise , reception is great.

Problem: - push buttons?

The code uses the switch on the rotary or a standard push button to change the range step  tuning (10khz,1khz,100hz etc etc.
It uses pin 46 (atmega 2560) but I tried it on other pins as well.
I cant seem to make the button work. If i hold the wire which is connected to the pin, the range starts changing(capacitive effect I guess)  but If i try a button it does not change the step tuning.
I have tried using _pullup command - no change.
Also tried 10k pullup resistor (pin to resistor to 5v) - no change.
Tried 10k to ground - no change.
Tried direct - to pin to button - 
Also tried other push buttons to make sure they were good.

This should be simple but I am running out of ideas.

If any one can provide a solution or some ideas to try, for this one button , it will probably solve the same issues with the remaining buttons .
Any help would be much appreciated

Joe
VE1BWV

 
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSerifBold12pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <MCUFRIEND_kbv.h>
#include <Wire.h>
#include <Rotary.h>
#include <si5351.h>
 
#define  ROT_L1_PIN 49// rotary A
#define  ROT_R1_PIN 48//rotaryA
#define  LED_R_PIN 45
#define  LED_G_PIN 44
#define  LED_B_PIN 47
#define ROT_SW1_PIN 46//   <<<<<<< this is the step range tuning button >>>>>>>>>>>
#define  ROT_LEFT  1
#define  ROT_RIGHT 2
#define  ROT_STAY  3
#define ROT_MIN        700000UL               // Lower frequency limit
#define ROT_MAX        5000000000UL
#define CALLSIGN "PD8W"
#define BITX40   "BITX40 V3c"
 
int ROT_d = 10;
int mode = 0;
int oldMode = -1;
 
Si5351 si5351;
Rotary r = Rotary(ROT_L1_PIN, ROT_R1_PIN);
volatile uint32_t LSB = 1199850000ULL;
volatile uint32_t USB = 1200150000ULL;
volatile uint32_t bfo = LSB; //start in lsb
//In this sketch the start frequency will be 7.100000 Mhz
volatile uint32_t vfo = 709980000ULL / SI5351_FREQ_MULT; //start freq - change to suit
boolean changed_f = 0;
String tbfo = "";
long lastMilis = 0;       // to track the last sampled time
long val1a, val1b;
long dirRot1 = ROT_STAY;
long valRot1 = vfo;
long oldVal1 = -1;
//---------------------------- --- Set Optional Features here ------------------------------ --------
//Remove comment (//) from the option you want to use. Pick only one
#define IF_Offset //Output is the display plus or minus the bfo frequency
//#define Direct_conversion //What you see on display is what you get
//#define FreqX4  //output is four times the display frequency
//---------------------------- ------------------------------ ------------------------------ ----------
 
MCUFRIEND_kbv tft;
 
const int  buttonPin = 52;    // pins that  pushbuttons are attached  for tx/rx   mode/ etc
const int  buttonPin2 = 53;
const int  buttonPin3 = 51;
const int  buttonPin4 = 50;
const int  buttonPin5 = 43;
 
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonPushCounter2 = 0;   // counter for the number of button presses
int buttonPushCounter3 = 0;   // counter for the number of button presses
int buttonPushCounter4 = 0;   // counter for the number of button presses
int buttonPushCounter5 = 0;   // counter for the number of button presses
 
 
int buttonState = 0;         // current state of the button
int buttonState2 = 0;         // current state of the button
int buttonState3 = 0;         // current state of the button
int buttonState4 = 0;         // current state of the button
int buttonState5 = 0;         // current state of the button
 
 
int lastButtonState = 0;     // previous state of the button
int lastButtonState2 = 0;     // previous state of the button
int lastButtonState3 = 0;     // previous state of the button
int lastButtonState4 = 0;     // previous state of the button
int lastButtonState5 = 0;     // previous state of the button
 
// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x0353
#define OBLUE   0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x7BEF
#define DARKGREY 0x18E3
 
uint16_t g_identifier;
 
void setup(void) {
  Serial.begin(9600);
  pinMode(LED_R_PIN, OUTPUT);
  pinMode(LED_G_PIN, OUTPUT);
  pinMode(LED_B_PIN, OUTPUT);
  Wire.begin();
 
  si5351.set_correction(140); //**mine. There is a calibration sketch in File/Examples/si5351Arduino- Jason
  //where you can determine the correction by using the serial monitor.
 
  //initialize the Si5351
  si5351.init(SI5351_CRYSTAL_ LOAD_8PF, 0); //If you're using a 27Mhz crystal, put in 27000000 instead of 0
  // 0 is the default crystal frequency of 25Mhz.
 
  si5351.set_pll(SI5351_PLL_ FIXED, SI5351_PLLA);
  // Set CLK0 to output the starting "vfo" frequency as set above by vfo = ?
 
#ifdef IF_Offset
  uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
  si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
  // seems not used : volatile uint32_t vfoT = (vfo * SI5351_FREQ_MULT) - bfo;
  tbfo = "LSB";
  // Set CLK2 to output bfo frequency
  si5351.set_freq( bfo, 0, SI5351_CLK2);
  si5351.drive_strength(SI5351_ CLK0, SI5351_DRIVE_2MA); //you can set this to 2MA, 4MA, 6MA or 8MA
  //si5351.drive_strength( SI5351_CLK1,SI5351_DRIVE_2MA); //be careful though - measure into 50ohms
  //si5351.drive_strength( SI5351_CLK2,SI5351_DRIVE_2MA); //
#endif
 
#ifdef Direct_conversion
  si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
#ifdef FreqX4
  si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
  int i = 0;
  pinMode(ROT_L1_PIN, INPUT);
  pinMode(ROT_R1_PIN, INPUT);
  digitalWrite(ROT_L1_PIN, HIGH); //pull-up enable
  digitalWrite(ROT_R1_PIN, HIGH); //pull-up enable
 
  pinMode(ROT_SW1_PIN, INPUT); //  non pull up  <<<<<<<<<<<<<<<<<<< range step tuning  button>>>>>>>>>>>>>>>>>
 
  uint32_t when = millis();
  //    while (!Serial) ;   //hangs a Leonardo until you connect a Serial
  if (!Serial) delay(5000);           //allow some time for Leonardo
  Serial.println("Serial took " + String((millis() - when)) + "ms to start");
  static uint16_t identifier;
  //    tft.reset();                 //we can't read ID on 9341 until begin()
  g_identifier = tft.readID(); //
  Serial.print("ID = 0x");
  Serial.println(g_identifier, HEX);
  if (g_identifier == 0x00D3 || g_identifier == 0xD3D3) g_identifier = 0x9481; // write-only shield
  if (g_identifier == 0xFFFF) g_identifier = 0x9341; // serial
  //    g_identifier = 0x9329;                             // force ID
  tft.begin(g_identifier);
 
#if defined(MCUFRIEND_KBV_H_)
  uint16_t scrollbuf[320];    // my biggest screen is 320x480
#define READGRAM(x, y, buf, w, h)  tft.readGRAM(x, y, buf, w, h)
#else
  uint16_t scrollbuf[320];    // Adafruit only does 240x320
  // Adafruit can read a block by one pixel at a time
  int16_t  READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
  {
    uint16_t *p;
    for (int row = 0; row < h; row++) {
      p = block + row * w;
      for (int col = 0; col < w; col++) {
        *p++ = tft.readPixel(x + col, y + row);
      }
    }
  }
#endif
  uint8_t aspect;
  uint16_t pixel;
  char *colorname[] = {" PD8W"};
  uint16_t colormask[] = { 0x001F, 0x7BEF,  };
  uint16_t dx, rgb, n, s, wid, ht;
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  tft.drawRect(74, 58, 71, 13, GREY);
  tft.setTextSize(1);
  tft.setCursor(77, 61);
  tft.setTextColor(GREY, BLACK);
  tft.println("WB-Software");
  tft.drawRect(74, 70, 180, 100, GREY);
  tft.fillRect(75, 70, 69, 1, BLACK);
  tft.setFont();
  tft.setCursor(91, 85);
  tft.setTextColor(CYAN, BLACK);
  tft.println("Powered and developed by");
  tft.setFont(& FreeSansBold12pt7b);
  tft.setTextSize(1);
  tft.setCursor(130, 128);
  tft.setTextColor(WHITE, BLACK);
  tft.println("PD8W ");
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(118, 145);
  tft.setTextColor(YELLOW, BLACK);
  tft.println("www.pd8w.com (c)");
  tft.drawRect(183, 169, 71, 13, GREY);
  tft.fillRect(183, 169, 70, 1, BLACK);
  tft.setTextSize(1);
  tft.setCursor(186, 171);
  tft.setTextColor(GREY, BLACK);
  tft.println("version 1.0");
  delay(5000);
  tft.fillScreen(BLACK);
  tft.setFont();
  aspect = (0 + 0) & 3;
  tft.setRotation(aspect + 1);
  wid = tft.width();
  ht = tft.height();
 
  dx = wid / 32;
  for (n = 0; n < 32; n++) {
    rgb = n * 8;
    rgb = tft.color565(rgb, rgb, rgb);
    tft.fillRect(n * dx, 10, dx, 44, rgb & colormask[aspect]);
  }
  tft.setTextSize(2);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(0, 24);
  tft.print(colorname[aspect]);
  tft.setTextColor(WHITE);
  tft.print(" BITX40");
  tft.setTextSize(1);
  tft.println(" TRANSCEIVER");
  tft.setCursor(285, 25);
  tft.println("21:45");
#if defined(MCUFRIEND_KBV_H_)
  extern const uint8_t penguin[];
  tft.setAddrWindow(240, 5, 279, 59);
  tft.pushColors(penguin, 1600, 1);
#endif
  tft.setFont();
  tft.setTextSize(1);
  tft.setTextColor(GREY, BLACK);
  tft.setCursor(265, 64);
  tft.println("- 86 dBM");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(20, 125);
  tft.setTextColor(RED, BLACK);
  tft.println("VFO");
  tft.setTextSize(2);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(29, 145);
  tft.setTextColor(CYAN, BLACK);
  tft.println("A");
  tft.setTextSize(2);
  tft.setFont(& FreeSansBold12pt7b);
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(150, 155);
  tft.setTextColor(GREY, BLACK);
  tft.print("AGC-S");
  tft.setCursor(215, 155);
  tft.println("100 Hz");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(270, 145);
  tft.setTextColor(WHITE, BLACK);
  tft.println("LSB");
  tft.fillRect(20, 60, 24, 15, GREEN);
  tft.drawRect(50, 60, 24, 15, RED);
  tft.fillRect(80, 60, 28, 15, GREY);
  tft.drawRect(108, 60, 31, 15, GREY);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(20, 71);
  tft.setFont();
  tft.setTextColor(BLACK);
  tft.println(" RX ");
  tft.setCursor(50, 64);
  tft.setTextColor(RED);
  tft.println(" TX ");
  tft.setCursor(81, 64);
  tft.setTextColor(BLACK);
  tft.println(" BW ");
  tft.setCursor(107, 63);
  tft.setTextColor(GREY);
  tft.println(" 3.0k ");
  tft.drawLine(155, 72, 160, 60, WHITE);
  tft.drawLine(176, 60, 181, 72, WHITE);
  tft.fillRect(161, 60, 15, 1, WHITE);
  tft.fillRect(148, 72, 42, 1, WHITE);
  tft.fillRect(168, 68, 1, 4, WHITE);
  tft.setCursor(39, 180);
  tft.print("S");
  tft.setCursor(59, 180);
  tft.print("1");
  tft.setCursor(84, 180);
  tft.print("3");
  tft.setCursor(110, 180);
  tft.print("5");
  tft.setCursor(136, 180);
  tft.print("7");
  tft.setCursor(162, 180);
  tft.print("9");
  tft.setTextColor(RED);
  tft.setCursor(186, 180);
  tft.print("+20");
  tft.setCursor(218, 180);
  tft.print("+40");
  tft.setCursor(250, 180);
  tft.print("+60dB");
  tft.fillRect(60, 189, 2, 3, WHITE);
  tft.fillRect(73, 189, 2, 3, WHITE);
  tft.fillRect(86, 189, 2, 3, WHITE);
  tft.fillRect(99, 189, 2, 3, WHITE);
  tft.fillRect(112, 189, 2, 3, WHITE);
  tft.fillRect(125, 189, 2, 3, WHITE);
  tft.fillRect(138, 189, 2, 3, WHITE);
  tft.fillRect(151, 189, 2, 3, WHITE);
  tft.fillRect(164, 189, 2, 3, WHITE);
  tft.fillRect(196, 189, 2, 3, RED);
  tft.fillRect(228, 189, 2, 3, RED);
  tft.fillRect(260, 189, 2, 3, RED);
  for (s = 50; s < 167; s++) {
    tft.fillRect(s, 192, 1, 1, WHITE);
  }
  for (s = 167; s < 271; s++) {
    tft.fillRect(s, 191, 1, 2, RED);
  }
  for (s = 50; s < 270; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, GREY);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
    tft.fillRect(s, 203, 3, 1, WHITE);
  }
  for (i = 0; i < 1; i++) {
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 52; s <= 165; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, BLUE);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 165; s <= 270; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, RED);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    for (s = 270; s >= 168; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, RED);
      delay(2);
    }
    tft.fillRect(166, 193, 2, 10, GREY);
    tft.fillRect(165, 193, 1, 10, BLACK);
    for (s = 164; s >= 52; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, BLUE);
      delay(2);
    }
  }
  for (s = 50; s < 164; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, BLUE);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  for (s = 164; s < 181; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, RED);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  tft.fillRect(50, 193, 2, 10, WHITE);
  tft.setCursor(30, 206);
  tft.setTextColor(GREY, BLACK);
  tft.print("Po 0");
  tft.setCursor(110, 206);
  tft.print("25");
  tft.setCursor(162, 206);
  tft.print("50");
  tft.setCursor(255, 206);
  tft.print("100%");
  tft.setCursor(0, 231);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(1);
  tft.print("Version 1.0 - WB-Software (c) 2016");
  tft.print(" GPU:");
  tft.print(tft.readID(), HEX);
  tft.print("@");
  tft.print(0.000001 * F_CPU);
  tft.println("MHz");
  delay(2000);
  tft.fillRect(0, 230, 320, 10, BLACK);
  tft.fillRect(2, 225, 60, 15, DARKGREY);
  tft.drawRect(2, 225, 60, 15, GREY);
  tft.setCursor(16, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("METER");
  tft.fillRect(66, 225, 60, 15, DARKGREY);
  tft.drawRect(66, 225, 60, 15, GREY);
  tft.setCursor(75, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("VFO/MEM");
  tft.fillRect(130, 225, 60, 15, DARKGREY);
  tft.drawRect(130, 225, 60, 15, GREY);
  tft.setCursor(142, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("SSB/CW");
  tft.fillRect(194, 225, 60, 15, DARKGREY);
  tft.drawRect(194, 225, 60, 15, GREY);
  tft.setCursor(200, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("TRANSMIT");
  tft.fillRect(258, 225, 60, 15, DARKGREY);
  tft.drawRect(258, 225, 60, 15, GREY);
  tft.setCursor(271, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("FILTER");
}
 
void loop(void) {
  digitalWrite(LED_R_PIN, HIGH);
  digitalWrite(LED_G_PIN, HIGH);
  digitalWrite(LED_B_PIN, LOW);
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      buttonPushCounter++;
      switch (buttonPushCounter) {
        case 1:
          Serial.println("4.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 4.0k ");
          tft.drawLine(152, 72, 157, 60, WHITE);
          tft.drawLine(181, 60, 186, 72, WHITE);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 2:
          Serial.println("1.8k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 1.8k ");
          tft.drawLine(160, 72, 165, 60, WHITE);
          tft.drawLine(171, 60, 176, 72, WHITE);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(165, 60, 6, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 3:
          Serial.println("2.4k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 2.4k ");
          tft.drawLine(158, 72, 163, 60, WHITE);
          tft.drawLine(173, 60, 178, 72, WHITE);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.fillRect(163, 60, 10, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 4:
          Serial.println("3.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 3.0k ");
          tft.drawLine(155, 72, 160, 60, WHITE);
          tft.drawLine(176, 60, 181, 72, WHITE);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.fillRect(161, 60, 15, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          buttonPushCounter = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState2 != lastButtonState2) {
    if (buttonState2 == HIGH) {
      buttonPushCounter2++;
      switch (buttonPushCounter2) {
        case 1:
          Serial.print("TX: button ");
          Serial.println( buttonPushCounter2);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(50, 60, 24, 15, RED);
          tft.setFont();
          tft.setTextSize(1);
          tft.setCursor(50, 64);
          tft.setTextColor(WHITE);
          tft.println(" TX ");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.drawRect(20, 60, 24, 15, GREEN);
          tft.setTextColor(GREEN);
          tft.setCursor(20, 64);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(RED);
          tft.println("Transmitting");
          break;
        case 2:
          Serial.println("RX");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.fillRect(20, 60, 24, 15, GREEN);
          tft.fillRect(50, 60, 24, 15, BLACK);
          tft.drawRect(50, 60, 24, 15, RED);
          tft.setTextColor(RED);
          tft.setCursor(50, 64);
          tft.println(" TX ");
          tft.setCursor(20, 64);
          tft.setTextColor(BLACK);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(GREEN);
          tft.println("Receiving");
          delay(1000);
          tft.fillRect(18, 78, 100, 10, BLACK);
          buttonPushCounter2 = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState3 = digitalRead(buttonPin3);
  if (buttonState3 != lastButtonState3) {
    if (buttonState3 == HIGH) {
      buttonPushCounter3++;
      switch (buttonPushCounter3) {
        case 1:
          Serial.println("USB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("USB");
          break;
        case 2:
          Serial.println("CW");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("CW");
          break;
        case 3:
          Serial.println("LSB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("LSB");
          buttonPushCounter3 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState4 = digitalRead(buttonPin4);
  if (buttonState4 != lastButtonState4) {
    if (buttonState4 == HIGH) {
      buttonPushCounter4++;
      switch (buttonPushCounter4) {
        case 1:
          Serial.println("VFO B");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("B");
          break;
        case 2:
          Serial.println("MEM");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(YELLOW, BLACK);
          tft.println("MEM");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("001");
          break;
        case 3:
          Serial.println("VFO A");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 20, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("A");
          buttonPushCounter4 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState5 = digitalRead(buttonPin5);
  if (buttonState5 != lastButtonState5) {
    if (buttonState5 == HIGH) {
      buttonPushCounter5++;
      int s = 0;
      int t = 0;
      int i = 0;
      switch (buttonPushCounter5) {
        case 1:
          Serial.println("SWR");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("SWR");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(48, 206);
          tft.print("1");
          tft.setCursor(70, 206);
          tft.print("1.5");
          tft.setCursor(105, 206);
          tft.print("2");
          tft.setCursor(125, 206);
          tft.print("2.5");
          tft.setCursor(162, 206);
          tft.print("3");
          tft.drawCircle(260, 208, 3, GREY);
          tft.drawCircle(266, 208, 3, GREY);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 70; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              delay(15);
            }
            for (s = 70; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 50; s < 90; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 90; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
          }
          break;
        case 2:
          Serial.println("ALC");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("ALC");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 203, 116, 2, RED);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 166; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(5);
            }
            for (s = 166; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(5);
            }
          }
          break;
        case 3:
          Serial.println("COMP");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(23, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("COMP");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 192, 9, 12, GREY);
          tft.setTextColor(BLACK, GREY);
          tft.setCursor(52, 195);
          tft.print("0");
          tft.fillRect(88, 192, 9, 12, GREY);
          tft.setCursor(90, 195);
          tft.print("5");
          tft.fillRect(130, 192, 13, 12, GREY);
          tft.setCursor(130, 195);
          tft.print("10");
          tft.fillRect(170, 192, 13, 12, GREY);
          tft.setCursor(170, 195);
          tft.print("15");
          tft.fillRect(211, 192, 14, 12, GREY);
          tft.setCursor(212, 195);
          tft.print("20");
          tft.fillRect(256, 192, 13, 12, GREY);
          tft.setCursor(257, 195);
          tft.print("dB");
          for (i = 0; i < 3; i++) {
            for (s = 60; s <= 86; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 98; s <= 128; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 128; s >= 96; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            for (s = 86; s >= 58; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            tft.setCursor(52, 195);
            tft.print("0");
            tft.fillRect(88, 192, 9, 12, GREY);
            tft.setCursor(90, 195);
            tft.print("5");
            tft.fillRect(130, 192, 13, 12, GREY);
            tft.setCursor(130, 195);
            tft.print("10");
            tft.fillRect(170, 192, 13, 12, GREY);
            tft.setCursor(170, 195);
            tft.print("15");
            tft.fillRect(211, 192, 14, 12, GREY);
            tft.setCursor(212, 195);
            tft.print("20");
            tft.fillRect(256, 192, 13, 12, GREY);
            tft.setCursor(257, 195);
            tft.print("dB");
          }
          break;
        case 4:
          Serial.println("ID");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("ID");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.setCursor(48, 206);
          tft.print("0");
          tft.setCursor(90, 206);
          tft.print("5");
          tft.setCursor(130, 206);
          tft.print("10");
          tft.setCursor(172, 206);
          tft.print("20");
          tft.setCursor(216, 206);
          tft.print("15");
          tft.setCursor(260, 206);
          tft.print("25A");
          tft.fillCircle(58, 209, 1, GREY);
          tft.fillCircle(66, 209, 1, GREY);
          tft.fillCircle(74, 209, 1, GREY);
          tft.fillCircle(82, 209, 1, GREY);
          tft.fillCircle(100, 209, 1, GREY);
          tft.fillCircle(108, 209, 1, GREY);
          tft.fillCircle(116, 209, 1, GREY);
          tft.fillCircle(124, 209, 1, GREY);
          tft.fillCircle(144, 209, 1, GREY);
          tft.fillCircle(152, 209, 1, GREY);
          tft.fillCircle(160, 209, 1, GREY);
          tft.fillCircle(168, 209, 1, GREY);
          tft.fillCircle(187, 209, 1, GREY);
          tft.fillCircle(195, 209, 1, GREY);
          tft.fillCircle(203, 209, 1, GREY);
          tft.fillCircle(211, 209, 1, GREY);
          tft.fillCircle(231, 209, 1, GREY);
          tft.fillCircle(239, 209, 1, GREY);
          tft.fillCircle(247, 209, 1, GREY);
          tft.fillCircle(255, 209, 1, GREY);
          tft.fillRect(92, 197, 1, 5, WHITE);
          tft.fillRect(136, 197, 1, 5, WHITE);
          tft.fillRect(178, 197, 1, 5, WHITE);
          tft.fillRect(222, 197, 1, 5, WHITE);
          tft.fillRect(264, 197, 1, 5, WHITE);
          for (i = 0; i < 1; i++) {
            for (s = 50; s < 170; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
            delay(1000);
            for (s = 170; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
          }
          break;
        case 5:
          Serial.println("S/PO");
          tft.fillRect(23, 180, 260, 40, BLACK);
          tft.setFont();
          tft.setTextColor(GREY, BLACK);
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(39, 180);
          tft.print("S");
          tft.setCursor(59, 180);
          tft.print("1");
          tft.setCursor(84, 180);
          tft.print("3");
          tft.setCursor(110, 180);
          tft.print("5");
          tft.setCursor(136, 180);
          tft.print("7");
          tft.setCursor(162, 180);
          tft.print("9");
          tft.setTextColor(RED);
          tft.setCursor(186, 180);
          tft.print("+20");
          tft.setCursor(218, 180);
          tft.print("+40");
          tft.setCursor(250, 180);
          tft.print("+60dB");
          tft.fillRect(60, 189, 2, 3, WHITE);
          tft.fillRect(73, 189, 2, 3, WHITE);
          tft.fillRect(86, 189, 2, 3, WHITE);
          tft.fillRect(99, 189, 2, 3, WHITE);
          tft.fillRect(112, 189, 2, 3, WHITE);
          tft.fillRect(125, 189, 2, 3, WHITE);
          tft.fillRect(138, 189, 2, 3, WHITE);
          tft.fillRect(151, 189, 2, 3, WHITE);
          tft.fillRect(164, 189, 2, 3, WHITE);
          tft.fillRect(196, 189, 2, 3, RED);
          tft.fillRect(228, 189, 2, 3, RED);
          tft.fillRect(260, 189, 2, 3, RED);
          for (s = 50; s < 167; s++) {
            tft.fillRect(s, 193, 1, 1, WHITE);
          }
          for (s = 166; s <= 271; s++) {
            tft.fillRect(s, 192, 1, 2, RED);
          }
          for (s = 50; s < 270; s = s + 3) {
            tft.fillRect(s, 193, 2, 10, GREY);
            tft.drawRect(s + 2, 200, 1, 10, BLACK);
            tft.fillRect(s, 203, 3, 1, WHITE);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          for (i = 0; i < 1; i++) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 52; s <= 165; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, BLUE);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 165; s <= 270; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, RED);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            for (s = 270; s >= 168; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, RED);
              delay(3);
            }
            tft.fillRect(166, 193, 2, 10, GREY);
            tft.fillRect(165, 193, 1, 10, BLACK);
            for (s = 164; s >= 52; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, BLUE);
              delay(3);
            }
          }
          for (s = 50; s < 164; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, BLUE);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          for (s = 164; s < 181; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, RED);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          buttonPushCounter5 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 }
 
  lastButtonState = buttonState;
  lastButtonState2 = buttonState2;
  lastButtonState3 = buttonState3;
  lastButtonState4 = buttonState4;
  lastButtonState5 = buttonState5;
 
  val1a = digitalRead( ROT_L1_PIN );
  val1b = digitalRead( ROT_R1_PIN );
  delay(1);
 
  // Rotary Encoder 1
  if ( val1a == HIGH && val1b == HIGH ) {
    if ( dirRot1 == ROT_LEFT ) {
      vfo += ROT_d;
      if (vfo > ROT_MAX) {
        vfo = ROT_MAX;
      }
    } else if ( dirRot1 == ROT_RIGHT ) {
      vfo -= ROT_d;
      if (vfo < ROT_MIN) {
        vfo = ROT_MIN;
      }
    }
    dirRot1 = ROT_STAY;
  } else {
    if ( val1a == LOW ) {
      dirRot1 = ROT_LEFT;
    }
    if ( val1b == HIGH ) {
      dirRot1 = ROT_RIGHT;
    }
  }
 
  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }
 
  if (oldVal1 != vfo) {
    oldVal1 = vfo;
    tft.fillRect(68, 110, 190, 40, BLACK);
    tft.fillRect(92, 145, 3, 3, WHITE);
    tft.fillRect(176, 145, 3, 3, WHITE);
    tft.setTextSize(2);
    tft.setFont(& FreeSansBold12pt7b);
    tft.setCursor(70, 145);
    tft.setTextColor(WHITE, BLACK);
    tft.println(oldVal1 + 200);
    // Serial.println(vfo);
#ifdef IF_Offset
    uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
    si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
    //you can also subtract the bfo to suit your needs
    //si5351.set_freq((vfo * SI5351_FREQ_MULT) + bfo  , SI5351_PLL_FIXED, SI5351_CLK0);
    //
    //    Serial.print("bfo : "); Serial.println(bfo);
    //    Serial.print("vfo : "); Serial.println(vfo);
    //    Serial.print("mult : "); Serial.println(int(SI5351_ FREQ_MULT));
    //    Serial.print("vco : "); Serial.println(vco);
    if (vfo >= 10000000ULL & tbfo != "USB")
    {
      bfo = USB;
      tbfo = "USB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from LSB to USB");
    }
    else if (vfo < 10000000ULL & tbfo != "LSB")
    {
      bfo = LSB;
      tbfo = "LSB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from USB to LSB");
    }
#endif
 
#ifdef Direct_conversion
    si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
 
#ifdef FreqX4
    si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
    delay(30);
  }
// DIGITAL STEP TUNING - SW1

  if ( digitalRead(ROT_SW1_PIN) ) {
    //delay(30);
    while (digitalRead(ROT_SW1_PIN)) {
      delay(1);
    }
    mode++;
    mode %= 5;
  }
}
 



Virus-free. www.avast.com







Re: More on troubleshooting.

KM4TRT
 

Hi Raj
C41  (I miscommuicated) is the cap going from the rf amp into the filter string, where I get a good signal on my friends board.
I checked all the parts that you mentioned and every thing was ok .   Took out T2 and found nothing wrong.
I probably will pull out the diodes as I don't think I can check them in their configuration. Then T1.\
I don't know how else to approach.
Andy

Re: BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Jack Purdum <econjack@...>
 

Joe:

Go to line 398 which reads:

  tft.setTextSize(defaultTextSize);
  g_identifier = 0x154;

and add the yellow line and see what happens to the message.

Jack, W8TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 7:26 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work



Jack, 

After changing:

 text size in line 302,340,376  the sw1, sw2, sw3  now look good - right place right size.
text size in line 850 was a 4 now a 3 - frequency correct size and fits perfect.

The next one is the meter size its to wide  when comparing it to your good display.  ---- looked where to change value  but could not find to make it narrower.
Your good display only goes as wide as the w in sw2.


The msg is till not in correct place - did not find a location where to force it lower



Getting closer........




Joe
VE1BWV


On Sun, Jun 18, 2017 at 1:53 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Hi Joe:

It appears that there are two issues: 1) The font size, and 2) the cursor addressing. If I recall correctly, both of those issues are determined by the Adafruit_GFX library, which the mcufriend library inherits from. Try first setting the setFont() calls to the smallest size (1) and see what it looks like. Then play around with the setCursor() calls to see how that impacts it. Only make one change at a time, recompile/upload so you can assess the impact of that one change. Let me know what you find out.

Jack. W9TEE



From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 12:36 PM
Subject: Re: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Jack,

Thanks for talking time off your busy schedule to look at this code.

I  liked the the PD8W display,  but it now appears more obvious the code is poorly structured and therefore a nightmare for someone like me trying to work out the issues.


I  looked at you suggested changes and they make sense - and reduce code

Unfortunately it induced other errors which I could not get around.


Hmmm,

I  am thinking if Jack is finding it difficult to read then I am in big trouble .....

I believe, its probably best to work with your code, which is supported and as you made clear,  more organized /  logical.

I have your board completed and just waiting for a mini_360 vr, the chokes and the 78L08.

My progress:

I have loaded your code and the display comes on . 
V: is hovering around 4.5 - so it appears alive
I also plugged the tft into a regular atmega2560 for testing / playing..

I am using an 2.8tft. 0x1289

Compared to the picture in your manual, I see this:


 mesg appears halfway up the screen and the bottom of the meter is about  1/2 inches from the bottom of the screen.

Any suggestions where the issue be?


Thanks Joe
VE1BWV


On Sat, Jun 17, 2017 at 11:18 PM, Jack Purdum via Groups.Io <econjack@...> wrote:
Man, that code is really hard to read. Evidently he doesn't believe in functions. Anyway, look at the code where the encode switch is read. If a switch push is sensed, the code does nothing. At least try this:


  if ( digitalRead(ROT_SW1_PIN) ) {
Serial.print("in digitalRead(), mode = ");
Serial.println(mode);
        //delay(30);
        while (digitalRead(ROT_SW1_PIN)) {
          delay(1);
        }
        mode++;
        mode %= 5;    // What the hell is the purpose of this if you only use 3 increment states???
  }


And take this code:


  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);    // Handle these differences in the function as offsets based on mode
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }

and turn it into this:

void ChangeIncrement(int mode) 
{
    char msg[9];
    int increment[] = {100, 1000, 10000};        //
        ROT_d = increment[mode];
        itoa(ROT_d, msg, DEC);
        strcat(msg, " Hz);
        Serial.println(msg);

        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println(msg);
}

and change the big switch/case above with the function call. If special formatting is needed, that can be done in the function.

Jack, W8TEE

From: Joe <joeman2116@...>
To: BITX20@groups.io
Sent: Saturday, June 17, 2017 4:17 PM
Subject: [BITX20] BITX40 TFT DISPLAY CODE - Coding A Control Button - Looking for Assistance to figure out why a Step Tuning button does not work

Hi All,

While waiting for some parts for another project, I came across some interesting code and have been doing some work on existing code by PD8W.
I have tried to contact him for some help but he does not appear to be available.
He developed some code to add a 2.8inch tft to the bitx40.  The display is interesting and uses a rotary with the sg5351 with an atmega2560.

I have made Progress:

The display works fine.
The Vfo dial changes the sg5351 dds
When i disconnect the current raduino board and the vfo connector on my bit40, then connect my test unit, I can tune fine, no clicks or noise , reception is great.

Problem: - push buttons?

The code uses the switch on the rotary or a standard push button to change the range step  tuning (10khz,1khz,100hz etc etc.
It uses pin 46 (atmega 2560) but I tried it on other pins as well.
I cant seem to make the button work. If i hold the wire which is connected to the pin, the range starts changing(capacitive effect I guess)  but If i try a button it does not change the step tuning.
I have tried using _pullup command - no change.
Also tried 10k pullup resistor (pin to resistor to 5v) - no change.
Tried 10k to ground - no change.
Tried direct - to pin to button - 
Also tried other push buttons to make sure they were good.

This should be simple but I am running out of ideas.

If any one can provide a solution or some ideas to try, for this one button , it will probably solve the same issues with the remaining buttons .
Any help would be much appreciated

Joe
VE1BWV

 
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSerifBold12pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <MCUFRIEND_kbv.h>
#include <Wire.h>
#include <Rotary.h>
#include <si5351.h>
 
#define  ROT_L1_PIN 49// rotary A
#define  ROT_R1_PIN 48//rotaryA
#define  LED_R_PIN 45
#define  LED_G_PIN 44
#define  LED_B_PIN 47
#define ROT_SW1_PIN 46//   <<<<<<< this is the step range tuning button >>>>>>>>>>>
#define  ROT_LEFT  1
#define  ROT_RIGHT 2
#define  ROT_STAY  3
#define ROT_MIN        700000UL               // Lower frequency limit
#define ROT_MAX        5000000000UL
#define CALLSIGN "PD8W"
#define BITX40   "BITX40 V3c"
 
int ROT_d = 10;
int mode = 0;
int oldMode = -1;
 
Si5351 si5351;
Rotary r = Rotary(ROT_L1_PIN, ROT_R1_PIN);
volatile uint32_t LSB = 1199850000ULL;
volatile uint32_t USB = 1200150000ULL;
volatile uint32_t bfo = LSB; //start in lsb
//In this sketch the start frequency will be 7.100000 Mhz
volatile uint32_t vfo = 709980000ULL / SI5351_FREQ_MULT; //start freq - change to suit
boolean changed_f = 0;
String tbfo = "";
long lastMilis = 0;       // to track the last sampled time
long val1a, val1b;
long dirRot1 = ROT_STAY;
long valRot1 = vfo;
long oldVal1 = -1;
//---------------------------- --- Set Optional Features here ------------------------------ --------
//Remove comment (//) from the option you want to use. Pick only one
#define IF_Offset //Output is the display plus or minus the bfo frequency
//#define Direct_conversion //What you see on display is what you get
//#define FreqX4  //output is four times the display frequency
//---------------------------- ------------------------------ ------------------------------ ----------
 
MCUFRIEND_kbv tft;
 
const int  buttonPin = 52;    // pins that  pushbuttons are attached  for tx/rx   mode/ etc
const int  buttonPin2 = 53;
const int  buttonPin3 = 51;
const int  buttonPin4 = 50;
const int  buttonPin5 = 43;
 
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonPushCounter2 = 0;   // counter for the number of button presses
int buttonPushCounter3 = 0;   // counter for the number of button presses
int buttonPushCounter4 = 0;   // counter for the number of button presses
int buttonPushCounter5 = 0;   // counter for the number of button presses
 
 
int buttonState = 0;         // current state of the button
int buttonState2 = 0;         // current state of the button
int buttonState3 = 0;         // current state of the button
int buttonState4 = 0;         // current state of the button
int buttonState5 = 0;         // current state of the button
 
 
int lastButtonState = 0;     // previous state of the button
int lastButtonState2 = 0;     // previous state of the button
int lastButtonState3 = 0;     // previous state of the button
int lastButtonState4 = 0;     // previous state of the button
int lastButtonState5 = 0;     // previous state of the button
 
// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x0353
#define OBLUE   0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x7BEF
#define DARKGREY 0x18E3
 
uint16_t g_identifier;
 
void setup(void) {
  Serial.begin(9600);
  pinMode(LED_R_PIN, OUTPUT);
  pinMode(LED_G_PIN, OUTPUT);
  pinMode(LED_B_PIN, OUTPUT);
  Wire.begin();
 
  si5351.set_correction(140); //**mine. There is a calibration sketch in File/Examples/si5351Arduino- Jason
  //where you can determine the correction by using the serial monitor.
 
  //initialize the Si5351
  si5351.init(SI5351_CRYSTAL_ LOAD_8PF, 0); //If you're using a 27Mhz crystal, put in 27000000 instead of 0
  // 0 is the default crystal frequency of 25Mhz.
 
  si5351.set_pll(SI5351_PLL_ FIXED, SI5351_PLLA);
  // Set CLK0 to output the starting "vfo" frequency as set above by vfo = ?
 
#ifdef IF_Offset
  uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
  si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
  // seems not used : volatile uint32_t vfoT = (vfo * SI5351_FREQ_MULT) - bfo;
  tbfo = "LSB";
  // Set CLK2 to output bfo frequency
  si5351.set_freq( bfo, 0, SI5351_CLK2);
  si5351.drive_strength(SI5351_ CLK0, SI5351_DRIVE_2MA); //you can set this to 2MA, 4MA, 6MA or 8MA
  //si5351.drive_strength( SI5351_CLK1,SI5351_DRIVE_2MA); //be careful though - measure into 50ohms
  //si5351.drive_strength( SI5351_CLK2,SI5351_DRIVE_2MA); //
#endif
 
#ifdef Direct_conversion
  si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
#ifdef FreqX4
  si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
#endif
 
  int i = 0;
  pinMode(ROT_L1_PIN, INPUT);
  pinMode(ROT_R1_PIN, INPUT);
  digitalWrite(ROT_L1_PIN, HIGH); //pull-up enable
  digitalWrite(ROT_R1_PIN, HIGH); //pull-up enable
 
  pinMode(ROT_SW1_PIN, INPUT); //  non pull up  <<<<<<<<<<<<<<<<<<< range step tuning  button>>>>>>>>>>>>>>>>>
 
  uint32_t when = millis();
  //    while (!Serial) ;   //hangs a Leonardo until you connect a Serial
  if (!Serial) delay(5000);           //allow some time for Leonardo
  Serial.println("Serial took " + String((millis() - when)) + "ms to start");
  static uint16_t identifier;
  //    tft.reset();                 //we can't read ID on 9341 until begin()
  g_identifier = tft.readID(); //
  Serial.print("ID = 0x");
  Serial.println(g_identifier, HEX);
  if (g_identifier == 0x00D3 || g_identifier == 0xD3D3) g_identifier = 0x9481; // write-only shield
  if (g_identifier == 0xFFFF) g_identifier = 0x9341; // serial
  //    g_identifier = 0x9329;                             // force ID
  tft.begin(g_identifier);
 
#if defined(MCUFRIEND_KBV_H_)
  uint16_t scrollbuf[320];    // my biggest screen is 320x480
#define READGRAM(x, y, buf, w, h)  tft.readGRAM(x, y, buf, w, h)
#else
  uint16_t scrollbuf[320];    // Adafruit only does 240x320
  // Adafruit can read a block by one pixel at a time
  int16_t  READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
  {
    uint16_t *p;
    for (int row = 0; row < h; row++) {
      p = block + row * w;
      for (int col = 0; col < w; col++) {
        *p++ = tft.readPixel(x + col, y + row);
      }
    }
  }
#endif
  uint8_t aspect;
  uint16_t pixel;
  char *colorname[] = {" PD8W"};
  uint16_t colormask[] = { 0x001F, 0x7BEF,  };
  uint16_t dx, rgb, n, s, wid, ht;
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  tft.drawRect(74, 58, 71, 13, GREY);
  tft.setTextSize(1);
  tft.setCursor(77, 61);
  tft.setTextColor(GREY, BLACK);
  tft.println("WB-Software");
  tft.drawRect(74, 70, 180, 100, GREY);
  tft.fillRect(75, 70, 69, 1, BLACK);
  tft.setFont();
  tft.setCursor(91, 85);
  tft.setTextColor(CYAN, BLACK);
  tft.println("Powered and developed by");
  tft.setFont(& FreeSansBold12pt7b);
  tft.setTextSize(1);
  tft.setCursor(130, 128);
  tft.setTextColor(WHITE, BLACK);
  tft.println("PD8W ");
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(118, 145);
  tft.setTextColor(YELLOW, BLACK);
  tft.println("www.pd8w.com (c)");
  tft.drawRect(183, 169, 71, 13, GREY);
  tft.fillRect(183, 169, 70, 1, BLACK);
  tft.setTextSize(1);
  tft.setCursor(186, 171);
  tft.setTextColor(GREY, BLACK);
  tft.println("version 1.0");
  delay(5000);
  tft.fillScreen(BLACK);
  tft.setFont();
  aspect = (0 + 0) & 3;
  tft.setRotation(aspect + 1);
  wid = tft.width();
  ht = tft.height();
 
  dx = wid / 32;
  for (n = 0; n < 32; n++) {
    rgb = n * 8;
    rgb = tft.color565(rgb, rgb, rgb);
    tft.fillRect(n * dx, 10, dx, 44, rgb & colormask[aspect]);
  }
  tft.setTextSize(2);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(0, 24);
  tft.print(colorname[aspect]);
  tft.setTextColor(WHITE);
  tft.print(" BITX40");
  tft.setTextSize(1);
  tft.println(" TRANSCEIVER");
  tft.setCursor(285, 25);
  tft.println("21:45");
#if defined(MCUFRIEND_KBV_H_)
  extern const uint8_t penguin[];
  tft.setAddrWindow(240, 5, 279, 59);
  tft.pushColors(penguin, 1600, 1);
#endif
  tft.setFont();
  tft.setTextSize(1);
  tft.setTextColor(GREY, BLACK);
  tft.setCursor(265, 64);
  tft.println("- 86 dBM");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(20, 125);
  tft.setTextColor(RED, BLACK);
  tft.println("VFO");
  tft.setTextSize(2);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(29, 145);
  tft.setTextColor(CYAN, BLACK);
  tft.println("A");
  tft.setTextSize(2);
  tft.setFont(& FreeSansBold12pt7b);
  tft.setFont();
  tft.setTextSize(1);
  tft.setCursor(150, 155);
  tft.setTextColor(GREY, BLACK);
  tft.print("AGC-S");
  tft.setCursor(215, 155);
  tft.println("100 Hz");
  tft.setFont(&FreeSans9pt7b);
  tft.setTextSize(1);
  tft.setCursor(270, 145);
  tft.setTextColor(WHITE, BLACK);
  tft.println("LSB");
  tft.fillRect(20, 60, 24, 15, GREEN);
  tft.drawRect(50, 60, 24, 15, RED);
  tft.fillRect(80, 60, 28, 15, GREY);
  tft.drawRect(108, 60, 31, 15, GREY);
  tft.setFont(&FreeSans9pt7b);
  tft.setTextColor(colormask[ aspect], BLACK);
  tft.setCursor(20, 71);
  tft.setFont();
  tft.setTextColor(BLACK);
  tft.println(" RX ");
  tft.setCursor(50, 64);
  tft.setTextColor(RED);
  tft.println(" TX ");
  tft.setCursor(81, 64);
  tft.setTextColor(BLACK);
  tft.println(" BW ");
  tft.setCursor(107, 63);
  tft.setTextColor(GREY);
  tft.println(" 3.0k ");
  tft.drawLine(155, 72, 160, 60, WHITE);
  tft.drawLine(176, 60, 181, 72, WHITE);
  tft.fillRect(161, 60, 15, 1, WHITE);
  tft.fillRect(148, 72, 42, 1, WHITE);
  tft.fillRect(168, 68, 1, 4, WHITE);
  tft.setCursor(39, 180);
  tft.print("S");
  tft.setCursor(59, 180);
  tft.print("1");
  tft.setCursor(84, 180);
  tft.print("3");
  tft.setCursor(110, 180);
  tft.print("5");
  tft.setCursor(136, 180);
  tft.print("7");
  tft.setCursor(162, 180);
  tft.print("9");
  tft.setTextColor(RED);
  tft.setCursor(186, 180);
  tft.print("+20");
  tft.setCursor(218, 180);
  tft.print("+40");
  tft.setCursor(250, 180);
  tft.print("+60dB");
  tft.fillRect(60, 189, 2, 3, WHITE);
  tft.fillRect(73, 189, 2, 3, WHITE);
  tft.fillRect(86, 189, 2, 3, WHITE);
  tft.fillRect(99, 189, 2, 3, WHITE);
  tft.fillRect(112, 189, 2, 3, WHITE);
  tft.fillRect(125, 189, 2, 3, WHITE);
  tft.fillRect(138, 189, 2, 3, WHITE);
  tft.fillRect(151, 189, 2, 3, WHITE);
  tft.fillRect(164, 189, 2, 3, WHITE);
  tft.fillRect(196, 189, 2, 3, RED);
  tft.fillRect(228, 189, 2, 3, RED);
  tft.fillRect(260, 189, 2, 3, RED);
  for (s = 50; s < 167; s++) {
    tft.fillRect(s, 192, 1, 1, WHITE);
  }
  for (s = 167; s < 271; s++) {
    tft.fillRect(s, 191, 1, 2, RED);
  }
  for (s = 50; s < 270; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, GREY);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
    tft.fillRect(s, 203, 3, 1, WHITE);
  }
  for (i = 0; i < 1; i++) {
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 52; s <= 165; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, BLUE);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    tft.fillRect(50, 193, 2, 10, WHITE);
    for (s = 165; s <= 270; s = s + 3) {
      tft.fillRect(s, 193, 2, 10, RED);
      tft.drawRect(s + 2, 193, 1, 10, BLACK);
      delay(2);
    }
    for (s = 270; s >= 168; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, RED);
      delay(2);
    }
    tft.fillRect(166, 193, 2, 10, GREY);
    tft.fillRect(165, 193, 1, 10, BLACK);
    for (s = 164; s >= 52; s = s - 3) {
      tft.fillRect(s, 193, 2, 10, GREY);
      tft.fillRect(s + 2, 193, 1, 10, BLACK);
      tft.drawRect(s - 2, 193, 2, 10, BLUE);
      delay(2);
    }
  }
  for (s = 50; s < 164; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, BLUE);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  for (s = 164; s < 181; s = s + 3) {
    tft.fillRect(s, 193, 2, 10, RED);
    tft.drawRect(s + 2, 193, 1, 10, BLACK);
  }
  tft.fillRect(50, 193, 2, 10, WHITE);
  tft.setCursor(30, 206);
  tft.setTextColor(GREY, BLACK);
  tft.print("Po 0");
  tft.setCursor(110, 206);
  tft.print("25");
  tft.setCursor(162, 206);
  tft.print("50");
  tft.setCursor(255, 206);
  tft.print("100%");
  tft.setCursor(0, 231);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(1);
  tft.print("Version 1.0 - WB-Software (c) 2016");
  tft.print(" GPU:");
  tft.print(tft.readID(), HEX);
  tft.print("@");
  tft.print(0.000001 * F_CPU);
  tft.println("MHz");
  delay(2000);
  tft.fillRect(0, 230, 320, 10, BLACK);
  tft.fillRect(2, 225, 60, 15, DARKGREY);
  tft.drawRect(2, 225, 60, 15, GREY);
  tft.setCursor(16, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("METER");
  tft.fillRect(66, 225, 60, 15, DARKGREY);
  tft.drawRect(66, 225, 60, 15, GREY);
  tft.setCursor(75, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("VFO/MEM");
  tft.fillRect(130, 225, 60, 15, DARKGREY);
  tft.drawRect(130, 225, 60, 15, GREY);
  tft.setCursor(142, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("SSB/CW");
  tft.fillRect(194, 225, 60, 15, DARKGREY);
  tft.drawRect(194, 225, 60, 15, GREY);
  tft.setCursor(200, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("TRANSMIT");
  tft.fillRect(258, 225, 60, 15, DARKGREY);
  tft.drawRect(258, 225, 60, 15, GREY);
  tft.setCursor(271, 229);
  tft.setTextColor(WHITE, DARKGREY);
  tft.print("FILTER");
}
 
void loop(void) {
  digitalWrite(LED_R_PIN, HIGH);
  digitalWrite(LED_G_PIN, HIGH);
  digitalWrite(LED_B_PIN, LOW);
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      buttonPushCounter++;
      switch (buttonPushCounter) {
        case 1:
          Serial.println("4.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 4.0k ");
          tft.drawLine(152, 72, 157, 60, WHITE);
          tft.drawLine(181, 60, 186, 72, WHITE);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 2:
          Serial.println("1.8k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 1.8k ");
          tft.drawLine(160, 72, 165, 60, WHITE);
          tft.drawLine(171, 60, 176, 72, WHITE);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.fillRect(165, 60, 6, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 3:
          Serial.println("2.4k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 2.4k ");
          tft.drawLine(158, 72, 163, 60, WHITE);
          tft.drawLine(173, 60, 178, 72, WHITE);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.drawLine(155, 72, 160, 60, BLACK);
          tft.drawLine(176, 60, 181, 72, BLACK);
          tft.fillRect(163, 60, 10, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          break;
        case 4:
          Serial.println("3.0k");
          tft.fillRect(108, 62, 28, 10, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(258, 225, 60, 15, GREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("FILTER");
          delay(100);
          tft.fillRect(258, 225, 60, 15, DARKGREY);
          tft.drawRect(258, 225, 60, 15, GREY);
          tft.setCursor(271, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("FILTER");
          tft.setCursor(107, 63);
          tft.setTextColor(GREY);
          tft.println(" 3.0k ");
          tft.drawLine(155, 72, 160, 60, WHITE);
          tft.drawLine(176, 60, 181, 72, WHITE);
          tft.drawLine(158, 72, 163, 60, BLACK);
          tft.drawLine(173, 60, 178, 72, BLACK);
          tft.drawLine(160, 72, 165, 60, BLACK);
          tft.drawLine(171, 60, 176, 72, BLACK);
          tft.fillRect(157, 60, 25, 1, BLACK);
          tft.drawLine(152, 72, 157, 60, BLACK);
          tft.drawLine(181, 60, 186, 72, BLACK);
          tft.fillRect(161, 60, 15, 1, WHITE);
          tft.fillRect(148, 72, 42, 1, WHITE);
          tft.fillRect(168, 68, 1, 4, WHITE);
          tft.fillRect(80, 78, 60, 2, GREY);
          delay(500);
          tft.fillRect(80, 78, 60, 2, BLACK);
          buttonPushCounter = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState2 != lastButtonState2) {
    if (buttonState2 == HIGH) {
      buttonPushCounter2++;
      switch (buttonPushCounter2) {
        case 1:
          Serial.print("TX: button ");
          Serial.println( buttonPushCounter2);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(50, 60, 24, 15, RED);
          tft.setFont();
          tft.setTextSize(1);
          tft.setCursor(50, 64);
          tft.setTextColor(WHITE);
          tft.println(" TX ");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.drawRect(20, 60, 24, 15, GREEN);
          tft.setTextColor(GREEN);
          tft.setCursor(20, 64);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(RED);
          tft.println("Transmitting");
          break;
        case 2:
          Serial.println("RX");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(194, 225, 60, 15, GREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("TRANSMIT");
          delay(100);
          tft.fillRect(194, 225, 60, 15, DARKGREY);
          tft.drawRect(194, 225, 60, 15, GREY);
          tft.setCursor(200, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("TRANSMIT");
          tft.fillRect(20, 60, 24, 15, BLACK);
          tft.fillRect(20, 60, 24, 15, GREEN);
          tft.fillRect(50, 60, 24, 15, BLACK);
          tft.drawRect(50, 60, 24, 15, RED);
          tft.setTextColor(RED);
          tft.setCursor(50, 64);
          tft.println(" TX ");
          tft.setCursor(20, 64);
          tft.setTextColor(BLACK);
          tft.println(" RX ");
          tft.fillRect(18, 78, 100, 10, BLACK);
          tft.setCursor(20, 80);
          tft.setTextColor(GREEN);
          tft.println("Receiving");
          delay(1000);
          tft.fillRect(18, 78, 100, 10, BLACK);
          buttonPushCounter2 = 0;
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
 
  buttonState3 = digitalRead(buttonPin3);
  if (buttonState3 != lastButtonState3) {
    if (buttonState3 == HIGH) {
      buttonPushCounter3++;
      switch (buttonPushCounter3) {
        case 1:
          Serial.println("USB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("USB");
          break;
        case 2:
          Serial.println("CW");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("CW");
          break;
        case 3:
          Serial.println("LSB");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(130, 225, 60, 15, GREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("SSB/CW");
          delay(100);
          tft.fillRect(130, 225, 60, 15, DARKGREY);
          tft.drawRect(130, 225, 60, 15, GREY);
          tft.setCursor(142, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("SSB/CW");
          tft.fillRect(269, 130, 44, 18, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(270, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("LSB");
          buttonPushCounter3 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState4 = digitalRead(buttonPin4);
  if (buttonState4 != lastButtonState4) {
    if (buttonState4 == HIGH) {
      buttonPushCounter4++;
      switch (buttonPushCounter4) {
        case 1:
          Serial.println("VFO B");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("B");
          break;
        case 2:
          Serial.println("MEM");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 25, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(YELLOW, BLACK);
          tft.println("MEM");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(WHITE, BLACK);
          tft.println("001");
          break;
        case 3:
          Serial.println("VFO A");
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(66, 225, 60, 15, GREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(66, 225, 60, 15, DARKGREY);
          tft.drawRect(66, 225, 60, 15, GREY);
          tft.setCursor(75, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("VFO/MEM");
          delay(100);
          tft.fillRect(20, 108, 40, 20, BLACK);
          tft.fillRect(20, 128, 40, 20, BLACK);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(20, 125);
          tft.setTextColor(RED, BLACK);
          tft.println("VFO");
          tft.setTextSize(2);
          tft.setFont(&FreeSans9pt7b);
          tft.setTextSize(1);
          tft.setCursor(29, 145);
          tft.setTextColor(CYAN, BLACK);
          tft.println("A");
          buttonPushCounter4 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 
  }
 
  buttonState5 = digitalRead(buttonPin5);
  if (buttonState5 != lastButtonState5) {
    if (buttonState5 == HIGH) {
      buttonPushCounter5++;
      int s = 0;
      int t = 0;
      int i = 0;
      switch (buttonPushCounter5) {
        case 1:
          Serial.println("SWR");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("SWR");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.fillRect(78, 197, 1, 5, WHITE);
          tft.fillRect(108, 197, 1, 5, WHITE);
          tft.fillRect(134, 197, 1, 5, WHITE);
          tft.fillRect(164, 197, 1, 5, WHITE);
          tft.setCursor(48, 206);
          tft.print("1");
          tft.setCursor(70, 206);
          tft.print("1.5");
          tft.setCursor(105, 206);
          tft.print("2");
          tft.setCursor(125, 206);
          tft.print("2.5");
          tft.setCursor(162, 206);
          tft.print("3");
          tft.drawCircle(260, 208, 3, GREY);
          tft.drawCircle(266, 208, 3, GREY);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 70; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              delay(15);
            }
            for (s = 70; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 50; s < 90; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
            for (s = 90; s >= 50; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              tft.fillRect(78, 197, 1, 5, WHITE);
              tft.fillRect(108, 197, 1, 5, WHITE);
              tft.fillRect(134, 197, 1, 5, WHITE);
              tft.fillRect(164, 197, 1, 5, WHITE);
              delay(15);
            }
          }
          break;
        case 2:
          Serial.println("ALC");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("ALC");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 203, 116, 2, RED);
          for (i = 0; i < 2; i++) {
            for (s = 50; s < 166; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(5);
            }
            for (s = 166; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(5);
            }
          }
          break;
        case 3:
          Serial.println("COMP");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(23, 194);
          tft.setTextColor(GREY, BLACK);
          tft.print("COMP");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
          }
          tft.fillRect(50, 192, 9, 12, GREY);
          tft.setTextColor(BLACK, GREY);
          tft.setCursor(52, 195);
          tft.print("0");
          tft.fillRect(88, 192, 9, 12, GREY);
          tft.setCursor(90, 195);
          tft.print("5");
          tft.fillRect(130, 192, 13, 12, GREY);
          tft.setCursor(130, 195);
          tft.print("10");
          tft.fillRect(170, 192, 13, 12, GREY);
          tft.setCursor(170, 195);
          tft.print("15");
          tft.fillRect(211, 192, 14, 12, GREY);
          tft.setCursor(212, 195);
          tft.print("20");
          tft.fillRect(256, 192, 13, 12, GREY);
          tft.setCursor(257, 195);
          tft.print("dB");
          for (i = 0; i < 3; i++) {
            for (s = 60; s <= 86; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 98; s <= 128; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(7);
            }
            for (s = 128; s >= 96; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            for (s = 86; s >= 58; s = s - 2) {
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(7);
            }
            tft.setCursor(52, 195);
            tft.print("0");
            tft.fillRect(88, 192, 9, 12, GREY);
            tft.setCursor(90, 195);
            tft.print("5");
            tft.fillRect(130, 192, 13, 12, GREY);
            tft.setCursor(130, 195);
            tft.print("10");
            tft.fillRect(170, 192, 13, 12, GREY);
            tft.setCursor(170, 195);
            tft.print("15");
            tft.fillRect(211, 192, 14, 12, GREY);
            tft.setCursor(212, 195);
            tft.print("20");
            tft.fillRect(256, 192, 13, 12, GREY);
            tft.setCursor(257, 195);
            tft.print("dB");
          }
          break;
        case 4:
          Serial.println("ID");
          tft.fillRect(23, 173, 260, 40, BLACK);
          tft.setFont();
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(28, 194);
          tft.setTextColor(GREY, BLACK);
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.print("ID");
          for (s = 50; s < 270; s = s + 2) {
            tft.fillRect(s, 193, 1, 10, GREY);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            tft.fillRect(s, 203, 2, 1, WHITE);
          }
          tft.setCursor(48, 206);
          tft.print("0");
          tft.setCursor(90, 206);
          tft.print("5");
          tft.setCursor(130, 206);
          tft.print("10");
          tft.setCursor(172, 206);
          tft.print("20");
          tft.setCursor(216, 206);
          tft.print("15");
          tft.setCursor(260, 206);
          tft.print("25A");
          tft.fillCircle(58, 209, 1, GREY);
          tft.fillCircle(66, 209, 1, GREY);
          tft.fillCircle(74, 209, 1, GREY);
          tft.fillCircle(82, 209, 1, GREY);
          tft.fillCircle(100, 209, 1, GREY);
          tft.fillCircle(108, 209, 1, GREY);
          tft.fillCircle(116, 209, 1, GREY);
          tft.fillCircle(124, 209, 1, GREY);
          tft.fillCircle(144, 209, 1, GREY);
          tft.fillCircle(152, 209, 1, GREY);
          tft.fillCircle(160, 209, 1, GREY);
          tft.fillCircle(168, 209, 1, GREY);
          tft.fillCircle(187, 209, 1, GREY);
          tft.fillCircle(195, 209, 1, GREY);
          tft.fillCircle(203, 209, 1, GREY);
          tft.fillCircle(211, 209, 1, GREY);
          tft.fillCircle(231, 209, 1, GREY);
          tft.fillCircle(239, 209, 1, GREY);
          tft.fillCircle(247, 209, 1, GREY);
          tft.fillCircle(255, 209, 1, GREY);
          tft.fillRect(92, 197, 1, 5, WHITE);
          tft.fillRect(136, 197, 1, 5, WHITE);
          tft.fillRect(178, 197, 1, 5, WHITE);
          tft.fillRect(222, 197, 1, 5, WHITE);
          tft.fillRect(264, 197, 1, 5, WHITE);
          for (i = 0; i < 1; i++) {
            for (s = 50; s < 170; s = s + 2) {
              tft.fillRect(s, 193, 1, 10, BLUE);
              tft.drawRect(s + 1, 193, 1, 10, BLACK);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
            delay(1000);
            for (s = 170; s >= 50; s = s - 2) {
 
              tft.fillRect(s, 193, 1, 10, GREY);
              tft.fillRect(s + 1, 193, 1, 10, BLACK);
              tft.drawRect(s - 1, 193, 1, 10, BLUE);
              delay(15);
              tft.fillRect(50, 193, 1, 10, WHITE);
              tft.fillRect(92, 197, 1, 5, WHITE);
              tft.fillRect(136, 197, 1, 5, WHITE);
              tft.fillRect(178, 197, 1, 5, WHITE);
              tft.fillRect(222, 197, 1, 5, WHITE);
              tft.fillRect(264, 197, 1, 5, WHITE);
            }
          }
          break;
        case 5:
          Serial.println("S/PO");
          tft.fillRect(23, 180, 260, 40, BLACK);
          tft.setFont();
          tft.setTextColor(GREY, BLACK);
          tft.setTextSize(1);
          tft.fillRect(2, 225, 60, 15, GREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(DARKGREY, GREY);
          tft.print("METER");
          delay(100);
          tft.fillRect(2, 225, 60, 15, DARKGREY);
          tft.drawRect(2, 225, 60, 15, GREY);
          tft.setCursor(16, 229);
          tft.setTextColor(WHITE, DARKGREY);
          tft.print("METER");
          delay(100);
          tft.setCursor(39, 180);
          tft.print("S");
          tft.setCursor(59, 180);
          tft.print("1");
          tft.setCursor(84, 180);
          tft.print("3");
          tft.setCursor(110, 180);
          tft.print("5");
          tft.setCursor(136, 180);
          tft.print("7");
          tft.setCursor(162, 180);
          tft.print("9");
          tft.setTextColor(RED);
          tft.setCursor(186, 180);
          tft.print("+20");
          tft.setCursor(218, 180);
          tft.print("+40");
          tft.setCursor(250, 180);
          tft.print("+60dB");
          tft.fillRect(60, 189, 2, 3, WHITE);
          tft.fillRect(73, 189, 2, 3, WHITE);
          tft.fillRect(86, 189, 2, 3, WHITE);
          tft.fillRect(99, 189, 2, 3, WHITE);
          tft.fillRect(112, 189, 2, 3, WHITE);
          tft.fillRect(125, 189, 2, 3, WHITE);
          tft.fillRect(138, 189, 2, 3, WHITE);
          tft.fillRect(151, 189, 2, 3, WHITE);
          tft.fillRect(164, 189, 2, 3, WHITE);
          tft.fillRect(196, 189, 2, 3, RED);
          tft.fillRect(228, 189, 2, 3, RED);
          tft.fillRect(260, 189, 2, 3, RED);
          for (s = 50; s < 167; s++) {
            tft.fillRect(s, 193, 1, 1, WHITE);
          }
          for (s = 166; s <= 271; s++) {
            tft.fillRect(s, 192, 1, 2, RED);
          }
          for (s = 50; s < 270; s = s + 3) {
            tft.fillRect(s, 193, 2, 10, GREY);
            tft.drawRect(s + 2, 200, 1, 10, BLACK);
            tft.fillRect(s, 203, 3, 1, WHITE);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          for (i = 0; i < 1; i++) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 52; s <= 165; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, BLUE);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            tft.fillRect(50, 193, 2, 10, WHITE);
            for (s = 165; s <= 270; s = s + 3) {
              tft.fillRect(s, 193, 2, 10, RED);
              tft.drawRect(s + 2, 193, 1, 10, BLACK);
              delay(3);
            }
            for (s = 270; s >= 168; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, RED);
              delay(3);
            }
            tft.fillRect(166, 193, 2, 10, GREY);
            tft.fillRect(165, 193, 1, 10, BLACK);
            for (s = 164; s >= 52; s = s - 3) {
              tft.fillRect(s, 193, 2, 10, GREY);
              tft.fillRect(s + 2, 193, 1, 10, BLACK);
              tft.drawRect(s - 2, 193, 2, 10, BLUE);
              delay(3);
            }
          }
          for (s = 50; s < 164; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, BLUE);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          for (s = 164; s < 181; s = s + 3) {
            tft.fillRect(50, 193, 2, 10, WHITE);
            tft.fillRect(s, 193, 2, 10, RED);
            tft.drawRect(s + 2, 193, 1, 10, BLACK);
            delay(3);
          }
          tft.fillRect(50, 193, 2, 10, WHITE);
          tft.setCursor(30, 206);
          tft.setTextColor(GREY, BLACK);
          tft.print("Po 0");
          tft.setCursor(110, 206);
          tft.print("25");
          tft.setCursor(162, 206);
          tft.print("50");
          tft.setCursor(255, 206);
          tft.print("100%");
          buttonPushCounter5 = 0;
          break;
        default:
          // if nothing else matches, do the default
          // default is optional
          break;
      }
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    }
    // Delay a little bit to avoid bouncing
    delay(50);
 }
 
  lastButtonState = buttonState;
  lastButtonState2 = buttonState2;
  lastButtonState3 = buttonState3;
  lastButtonState4 = buttonState4;
  lastButtonState5 = buttonState5;
 
  val1a = digitalRead( ROT_L1_PIN );
  val1b = digitalRead( ROT_R1_PIN );
  delay(1);
 
  // Rotary Encoder 1
  if ( val1a == HIGH && val1b == HIGH ) {
    if ( dirRot1 == ROT_LEFT ) {
      vfo += ROT_d;
      if (vfo > ROT_MAX) {
        vfo = ROT_MAX;
      }
    } else if ( dirRot1 == ROT_RIGHT ) {
      vfo -= ROT_d;
      if (vfo < ROT_MIN) {
        vfo = ROT_MIN;
      }
    }
    dirRot1 = ROT_STAY;
  } else {
    if ( val1a == LOW ) {
      dirRot1 = ROT_LEFT;
    }
    if ( val1b == HIGH ) {
      dirRot1 = ROT_RIGHT;
    }
  }
 
  if (oldMode != mode) {
    oldMode = mode;
    switch (mode) {
      //        case 1:
      //          Serial.println("1 Hz");
      //          break;
      case 0:
        Serial.println("100 Hz");
        ROT_d = 100;
        tft.fillRect(195, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(190, 107, 185, 102, 195, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("100 Hz");
        break;
      case 1:
        Serial.println("1  KHz");
        ROT_d = 1000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(165, 107, 160, 102, 170, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 KHz");
        break;
      case 2:
        Serial.println("10 KHz");
        ROT_d = 10000;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(212, 102, 20, 10, BLACK);
        tft.fillRect(64, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillTriangle(139, 107, 134, 102, 144, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(215, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 KHz");
        break;
      case 3:
        Serial.println("1 Hz");
        ROT_d = 1;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(75, 102, 20, 10, BLACK);
        tft.fillTriangle(242, 107, 237, 102, 247, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(225, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("1 Hz");
        break;
      case 4:
        Serial.println("10 Hz");
        ROT_d = 10;
        tft.fillRect(205, 154, 50, 10, BLACK);
        tft.fillRect(155, 102, 20, 10, BLACK);
        tft.fillRect(129, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillRect(230, 102, 20, 10, BLACK);
        tft.fillRect(184, 102, 20, 10, BLACK);
        tft.fillTriangle(218, 107, 213, 102, 223, 102, WHITE);
        tft.setFont();
        tft.setTextSize(1);
        tft.setCursor(220, 155);
        tft.setTextColor(GREY, BLACK);
        tft.println("10 Hz");
        break;
    }
    //Serial.print("sw:");
    //Serial.println(mode);
  }
 
  if (oldVal1 != vfo) {
    oldVal1 = vfo;
    tft.fillRect(68, 110, 190, 40, BLACK);
    tft.fillRect(92, 145, 3, 3, WHITE);
    tft.fillRect(176, 145, 3, 3, WHITE);
    tft.setTextSize(2);
    tft.setFont(& FreeSansBold12pt7b);
    tft.setCursor(70, 145);
    tft.setTextColor(WHITE, BLACK);
    tft.println(oldVal1 + 200);
    // Serial.println(vfo);
#ifdef IF_Offset
    uint32_t vco = bfo - (vfo * SI5351_FREQ_MULT);
    si5351.set_freq(vco, SI5351_PLL_FIXED, SI5351_CLK0);
    //you can also subtract the bfo to suit your needs
    //si5351.set_freq((vfo * SI5351_FREQ_MULT) + bfo  , SI5351_PLL_FIXED, SI5351_CLK0);
    //
    //    Serial.print("bfo : "); Serial.println(bfo);
    //    Serial.print("vfo : "); Serial.println(vfo);
    //    Serial.print("mult : "); Serial.println(int(SI5351_ FREQ_MULT));
    //    Serial.print("vco : "); Serial.println(vco);
    if (vfo >= 10000000ULL & tbfo != "USB")
    {
      bfo = USB;
      tbfo = "USB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from LSB to USB");
    }
    else if (vfo < 10000000ULL & tbfo != "LSB")
    {
      bfo = LSB;
      tbfo = "LSB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from USB to LSB");
    }
#endif
 
#ifdef Direct_conversion
    si5351.set_freq((vfo * SI5351_FREQ_MULT), SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
 
#ifdef FreqX4
    si5351.set_freq((vfo * SI5351_FREQ_MULT) * 4, SI5351_PLL_FIXED, SI5351_CLK0);
    tbfo = "";
#endif
    delay(30);
  }
// DIGITAL STEP TUNING - SW1

  if ( digitalRead(ROT_SW1_PIN) ) {
    //delay(30);
    while (digitalRead(ROT_SW1_PIN)) {
      delay(1);
    }
    mode++;
    mode %= 5;
  }
}
 



Virus-free. www.avast.com






Re: W8TEE TFT/VFO DDS adapter

Jack Purdum <econjack@...>
 

Yes, it's trying to "point" to the offending source line for the error. This message is saying that it cannot find the write_16() function. After some searching, I found that it is a macro, not a function:

#define write_16(x)   { PORTA = (x) >> 8; PORTC = x; }

For some reason, this macro is not being read into the program, but is still being called. It's being held out because the USING_16BIT_BUS symbolic constant is being set to zero. Because the missing macro is messing around with ports, I'm assuming its doing that to improve the speed of the library. Just for grins (and I don't expect this to work), copy the line above to a spot immediately after all of the #include preprocessor directives and tell me what happens to the error message.

Jack, W8TEE



From: Michael Hagen <motdog@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 2:40 PM
Subject: Re: [BITX20] W8TEE TFT/VFO DDS adapter

As suggested I am trying to get MCUFriend grafixtest to run.
After hard coding to use 16 bit I get this error.....
Is the Carrot underneath just a marker for pointing out the error?

C:\Users\Michael Hagen\Documents\Arduino\libraries\MCUFRIEND_kbv-master\MCUFRIEND_kbv.cpp:573:23: error: 'write_16' was not declared in this scope

         write_16(color);        //we could just do the strobe

                       ^
Strange, "^" I did not put it there.

Mike


On 6/18/2017 11:12 AM, Jack Purdum via Groups.Io wrote:
This error:

"error: 'write_16' was not declared in this scope"

suggests that in your code you used:

#define write_16

which probably needs to be written:

#define WRITE_16

since most C programmers write symbolic constants in upper case letters. C is case sensitive so WRITE_16 and  write_16 are different symbolic constants.

Jack, W8TEE

From: Michael Hagen <motdog@...>
To: BITX20@groups.io
Sent: Sunday, June 18, 2017 1:27 PM
Subject: Re: [BITX20] W8TEE TFT/VFO DDS adapter

Thanks,

I added the 16Bit define in C file.

now get error in Jack's code?

"error: 'write_16' was not declared in this scope"

Maybe there needs to be a ref to an external something?


I think my correct display type is "ILI9481"  Which I have seen 0XDBDB
returned in a test?

I looked at Rinky Dink documents.  I looks like it uses the Data d0-d15
on the top half of the right side double connector.

D37 and up.  The top pins are 5V.  Then d39 & d41 on the right side for
Wr and Rst.

d36 & 38 on the other side for RS and CS.  They say that's all on the
Mega they use on that connector?



On 6/18/2017 9:48 AM, Vince Vielhaber wrote:
>
> I haven't looked at the other responses yet, so I'm assuming you got
> that info.  If not, I think you'd need to add
>
> #define USES_16BIT_BUS
>
> at the top of libraries/MCUFRIEND_kbv/MCUFRIEND_kbv.cpp
>
> Did you try 0x8357 as the g_identifier?  I see that it's in the
> library so yours may just not be getting accessed correctly.
>
> Vince.
>
>
>
> On 06/18/2017 09:57 AM, Michael Hagen wrote:
>> I am looking for a file in MCUfriend?
>>
>> A header or C file?
>>
>> Is there a #define somewhere to use Mega 2560 Pins.
>>
>> Yes, I have it plugged directly to a Mega, so I would need that option?
>>
>>
>> I tried changing ID in Jacks new code.  Still nothing.  Default 0xD3D3.
>>
>>
>> Thanks, I don't know where to look?
>>
>> Mike,WA6ISP
>>
>>
>> On 6/18/2017 4:34 AM, Laurent CHABERT wrote:
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> *De :* BITX20@groups.io <BITX20@groups.io> de la part de Vince
>>> Vielhaber <vev@...>
>>> *Envoyé :* dimanche 18 juin 2017 05:00
>>> *À :* BITX20@groups.io
>>> *Objet :* Re: [BITX20] W8TEE TFT/VFO DDS adapter
>>>
>>>
>>> Did you try changing that line of code in the MCUFriend driver that
>>> Jack
>>> mentioned the other day?  That one's using the mega pins as opposed to
>>> the standard pins.
>>>
>>> Vince.
>>>
>>>
>>>
>>> On 06/17/2017 01:09 PM, Michael Hagen wrote:
>>> > Yes Rinky Dink works but I can't get any MCU Friend to work.  I spent
>>> > most of the day playing with it.
>>> >
>>> > My TFT is directly plugged into a Mega 2560.  Its pinouts fit like a
>>> > shield over the top of the 2560.
>>> >
>>> > Any hints to give me?  I don't know why  Rinky Dink works.
>>> >
>>> > I have run the ID program in MCUFriend, no ID.  I know that the
>>> package
>>> > says HX8357B for Driver?
>>> >
>>> > Mike, WA6ISP
>>> >
>>> >
>>> > On 6/16/2017 4:58 PM, Vince Vielhaber wrote:
>>> >> If the UTFT library works (the one from Rinky Dink) then the
>>> >> MCUFriend_kbv library should once you find the right parameters.
>>> UTFT
>>> >> is slow and a memory pig.
>>> >>
>>> >> Vince.
>>> >>
>>> >>
>>> >>
>>> >> On 06/16/2017 07:40 PM, Michael Hagen wrote:
>>> >>> Bought 2 of these displays.  Less than $8.  No Touch Screen. 36
>>> Pins,
>>> >>> not 40.
>>> >>> Uses 9481 Controller, package says Driver: HX8357B?
>>> >>>
>>> >>> Work fine but not so far with your recommended library (Friend?).
>>> >>> A library at Rinkey Dink Electronics works?
>>> >>>
>>> >>> Parallel transfer, not serial.
>>> >>> I did not look at whether you used serial or parallel?
>>> >>>
>>> >>> Mike, WA6ISP
>>> >>>
>>> https://www.aliexpress.com/item/Free-shipping-3-2-inch-TFT-LCD-screen-module-Ultra-HD-320X480-for-Arduino-MEGA-2560/32609807497.html?spm=2114.13010608.0.0.7MCWtA
>>>
>>> >>>
>>> >>>
>>> >>>
>>> >>
>>> >
>>> >
>>> >
>>> >
>>>
>>> --
>>>    Michigan VHF Corp.  http://www.nobucks.net/ http://www.CDupe.com/
>>>                            http://www.metalworkingfun.com
>>>
>>>
>>>
>>
>>
>






Virus-free. www.avast.com



Re: gluing toroids to board

Krishnakumar N
 

We can use silicon RTV neutral grade for long life & flexibility .

I am using it in my HF amplifiers with stands transportation jerks of the finished products even with larger toriods.

Krish, vu3nkk

 

From: BITX20@groups.io [mailto:BITX20@groups.io] On Behalf Of Ashhar Farhan
Sent: Sunday, June 18, 2017 1:33 PM
To: BITX20@groups.io
Subject: Re: [BITX20] gluing toroids to board

 

we use a quick-setting glue akin to superglue.

- f

 

On Sun, Jun 18, 2017 at 11:57 AM, <davidzdeb@...> wrote:

So while I was handling my board the other night, I lost my grip and knocked my hand into one of the toroids.  It came unglued from the board, but the wiring remained intact.  I was thinking of using hot glue to stick it back on but I thought I should check if there is a preferred way of adhering components to the board.  

 

Re: gluing toroids to board

Michael Hagen
 

Yes!

Just a Dab of Hot Glue works Perfect!

I mean like an 1/8" dab.


On 6/18/2017 6:56 PM, Sasi Nayar wrote:
Realising how delicate these toroids were, I hot glued them when I first got the board. They work fine and is sits there snug tight
Sasi
VK5SN