Skip to main content

Nov 20, 2024. Those who know will understand!

 // UTFT_Demo_320x240_Serial
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for serial modules with a screen
// resolution of 320x240 pixels.
//
// This program requires the UTFT library.
//
// ********************************************************************
// * IMPORTANT: Read the comments in the setup() function when        *
// * using the Watterott MI0283QT9 or the DisplayModule DM-TFT28-105. *
// ********************************************************************
//Pete Here> 5/14/2018 Got this to work with all functions for use with a 20 Meter Transceiver
// Now need to install buttons.



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

// Declare which fonts we will be using
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];


//if your LCD driver IC is ILI9341,please uncomment the line
UTFT myGLCD(CTE32_R2, 38, 39, 40, 41);
//if your LCD driver IC is SSD1289,please uncomment the line
//UTFT myGLCD(CTE32, 38, 39, 40, 41);

URTouch  myTouch( 6, 5, 4, 3, 2);


 
    
 
    
    #include <SPI.h>
   
    #include "Rotary.h"
    #include <toneAC.h>
    #define TONE_PIN 6
    #define NOTE_B5  988
    
    
    #if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
    #endif
    
    
    #define ENCODER_B   A10                     // Encoder pin A
    #define ENCODER_A   A11                  // Encoder pin B
    #define ENCODER_BTN  A3
    
    
   
    
    #include "si5351.h"
    #include "Wire.h"
    
     Si5351 si5351;
      long int frq;
    int_fast32_t rx = 16198500L; // Starting frequency of VFO
    int_fast32_t rx2=1; // variable to hold the updated frequency
    int_fast32_t increment = 100; // starting VFO update increment in HZ.
    int_fast32_t bfo =8998500L; // LSB
    String hertz = " 100";
    
    int buttonstate = 0;
    int buttonstate2 = 0;
    
    const int tonepin = 9; //Output for tune up purposes 988 Hz tone
    const int SW = A1; //selects upper or lower sideband
    const int SW1 = A2; // provides the TUNE fucntion
    const int LED = 8; //Controls the transmitter in TUNE simple 5 VDC reed relay
    byte ones,tens,hundreds,thousands,tenthousands,hundredthousands,millions ;  //Placeholders
   // int backlight =0;
    int i = 0;
    
   const int SM =A0;// Analog Pin A0 for the S Meter function
   int adcval = 0; // Analog Pin A0 for the S Meter function
   int val = 0;
    
    
    int buttonState = 0;
    int lastButtonState = 0;
    
    Rotary r = Rotary(A10,A11); // sets the pins the rotary encoder uses.  
    


void setup()

{myGLCD.clrScr();

  Serial.begin(9600);

         myGLCD.clrScr();
         myGLCD.InitLCD();
         myGLCD.fillScr(255,80, 00);
    
         PCICR |= (1 << PCIE2);
         PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
         sei();
         
         
 
         
         pinMode(SW, INPUT);   // Selects either USB or LSB`````
         digitalWrite(SW,HIGH);
         pinMode(SW1, INPUT); //Tune
         digitalWrite(SW1,HIGH);
         pinMode(LED, OUTPUT);
         digitalWrite(LED,LOW);
       //  pinMode(backlight, OUTPUT);
         pinMode(A3,INPUT); // Connect to a button that goes to GND on push
         pinMode(A1,INPUT); // IF sense **********************************************
        pinMode(A10, INPUT); digitalWrite(A10, HIGH);
        pinMode(A11, INPUT); digitalWrite(A11, HIGH);
        pinMode(A0,INPUT); digitalWrite(A0,LOW);
       
         digitalWrite(A3,HIGH);
         digitalWrite(A2,HIGH);
         digitalWrite(A1,HIGH); // init done
         // set backlight level
       
       
      
      //while (!Serial);
      //tft.begin();
      #if defined(__MK20DX128__) || defined(__MK20DX256__)
     // display.setBitrate(24000000);
      #endif
    
      
        //  initialize the Si5351
    
          si5351.init(SI5351_CRYSTAL_LOAD_8PF);
          si5351.set_correction(100);
          
          si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
          
        // si5351.set_freq(rx , SI5351_PLL_FIXED, SI5351_CLK0);
    
         
          si5351.set_freq(bfo, 0, SI5351_CLK2);
          
          si5351.drive_strength(SI5351_CLK0,SI5351_DRIVE_8MA);
          si5351.drive_strength(SI5351_CLK2,SI5351_DRIVE_8MA);
          
         
    
    }
    
    
    void setincrement(){
        if (increment == 10){increment = 100;  hertz = " 100";}
        else if (increment == 100){increment = 1000; hertz="  1K";}
        else if (increment == 1000){increment = 10000; hertz="  10K"; }
       else if (increment == 10000){increment = 100000; hertz=" 100K";}
       else if (increment == 100000){increment = 1000000; hertz="  1M ";}  
        else{increment = 10; hertz = "  10";};  

           
         
         delay(100); // Adjust this delay to speed up/slow down the button menu scroll speed.
    }
    
    
    ISR(PCINT2_vect) {
      unsigned char result = r.process();
      if (result) {    
        if (result == DIR_CW){rx=rx+(1*increment);} // account that rx = 1 times the frequency so the increment must be 4* or /.25
        else {rx = rx-(1*increment);};       
          if (rx >=18900000L){rx=rx2;}; // UPPER VFO LIMIT = 1X the opearting frequency + offset
          if (rx <=1200000L){rx=rx2;}; // LOWER VFO LIMIT = 1 X the opearting frequency + Offset
          
          }
    
    
     
            
      
    
    }
    
 
  // Watterott
// ---------
// The following two lines are needed for the MI0283QT9 display
// module to enable the backlight. If you are using any other
// display module these lines should be commented out.
// -------------------------------------------------------------
//  pinMode(9, OUTPUT);
//  digitalWrite(9, HIGH);
// -------------------------------------------------------------

// DisplayModule
// -------------
// The following 4 lines are needed for the DM-TFT28-105 display
// module to set the SS/CS pins for the other devices connected
// to the Arduino SPI pins. If you are using any other display
// module these lines should be commented out.
// -------------------------------------------------------------
//  pinMode(10,OUTPUT); digitalWrite(10,HIGH);  // TFT SS/CE
//  pinMode(8, OUTPUT); digitalWrite(8, HIGH);  // SD card SS/CE
//  pinMode(6, OUTPUT); digitalWrite(6, HIGH);  // Flash chip SS/CE
//  pinMode(4, OUTPUT); digitalWrite(4, HIGH);  // Touch controller SS/CE
// -------------------------------------------------------------


// Just get some random numbers

 
// Setup the LCD
      
 

void loop()
{          showFreq();
           checkMode(); //********Moved void checkBand out of the loop
           checkSideband();
           lastButtonState = buttonState;

           myGLCD.setBackColor(255,80,0);
          myGLCD.setColor(VGA_BLACK);
          myGLCD.setFont(BigFont);
          myGLCD.print(hertz, 190,51);
    
         
       adcval = analogRead(SM);  //S meter routine

        
        Serial.println(adcval);
        myGLCD.setColor(VGA_BLACK);
        myGLCD.fillRect(90,190,290,215);
       
        val= 30*log((adcval-200)/20);

        
       
        myGLCD.setColor(VGA_LIME);
        myGLCD.fillRect(95,198,95 + val,205);
       
        
        
        delay(20);
        
        
        
        Serial.println(val);
 
 
 

 
   
 
      myGLCD.setBackColor(255,80,0);
      myGLCD.setColor(VGA_WHITE);

      myGLCD.setFont(BigFont);
      myGLCD.print("Hybrid Wireless", CENTER, 10);
      myGLCD.setBackColor(255,80,0);
      myGLCD.setColor(VGA_WHITE);
      myGLCD.setFont(BigFont);
      myGLCD.print("N6QW Wizard of 91320", CENTER, 220);
      myGLCD.setBackColor(255,80,0);
      myGLCD.setColor(VGA_BLACK);
      myGLCD.setFont(BigFont);
      myGLCD.print("SMtr",15,190);
 
        myGLCD.setColor(VGA_BLACK);
        myGLCD.setFont(BigFont);
        myGLCD.print("S9", 185,173);
        myGLCD.setColor(VGA_BLACK);
        myGLCD.fillRect(95, 180, 97, 185);
        myGLCD.setColor(VGA_BLACK);
        myGLCD.fillRect(105, 180, 107, 185);
        myGLCD.setColor(VGA_BLACK);
        myGLCD.fillRect(118, 180, 120, 185);
        myGLCD.setColor(VGA_BLACK);
        myGLCD.fillRect(134, 180, 136, 185);
        myGLCD.setColor(VGA_BLACK);
        myGLCD.fillRect(150, 180, 152, 185);
        myGLCD.setColor(VGA_BLACK);
        myGLCD.fillRect(170, 180, 172, 185);
         
         
     showFreq();   

 

 


         
   
    {      
          
          
            myGLCD.setFont(BigFont);
            myGLCD.setBackColor(255,80,0);
            myGLCD.setColor(VGA_BLACK);
           myGLCD.print("Hz",280, 51);
          
            
           
           
          
         
         
   
      
        if (rx != rx2){  
          
            myGLCD.setFont(SevenSegNumFont);  // When you change frequency you don't have to screen clear! It paints it black
            myGLCD.setBackColor(255,80,0);
          //  myGLCD.setColor(VGA_BLACK);
          //  myGLCD.printNumI((rx-bfo),30,91);
           
              
            showFreq();

            
            si5351.set_freq(rx  , SI5351_PLL_FIXED, SI5351_CLK0);
            Serial.print(rx);
            si5351.set_freq(bfo  , SI5351_PLL_FIXED, SI5351_CLK2);
            rx2 = rx;
            
          
          
            
          
            
          }
          
        buttonstate = digitalRead(A3);
        if(buttonstate == LOW) {
            setincrement();
         
            
            myGLCD.setBackColor(255,80,0);
            myGLCD.setFont(BigFont);
            myGLCD.setColor(VGA_BLACK);
            myGLCD.print(hertz, 190,51);
            delay(10);
             
     
           
          
            showFreq();
        };
        
        delay(25);
        
      
    }  
}
     
         
       void checkMode(){
        buttonState = digitalRead(SW1); // creates a 10 second tuning pulse trani 50% duty cycle and makes TUNE appear on the screen
       if(buttonState != lastButtonState){
        if(buttonState == LOW){
        digitalWrite(LED,HIGH);
          
         myGLCD.setFont(BigFont);
        myGLCD.setColor(VGA_WHITE);
         
         myGLCD.print("TUNE", 130, 42);
        
         delay(12);
         for(int i = 0; i < 100; i++) {
         tone(9, NOTE_B5);
         myGLCD.setColor(VGA_LIME);   //Flashes the Icon during transmits
         myGLCD.fillCircle(282,39,8);
         delay(75);
         noTone(9);
         myGLCD.setColor(VGA_BLACK);
         myGLCD.fillCircle(282,39,8);
         delay(25);
         
         }
             
        }
       else{
         digitalWrite(LED,LOW);
         myGLCD.setFont(BigFont);    // This prints a Black TUNE over the RED TUNE and makes it disappear from the scereen
         myGLCD.setBackColor(255,80,0);
         myGLCD.setColor(255,80,0);
         myGLCD.print("TUNE", 130, 42);
         myGLCD.setColor(VGA_BLACK);
         myGLCD.fillCircle(282, 39, 8);
         
         noTone(9);
    
       }
          
      
         delay(40);
    
       }
         }
    
      void checkSideband(){
      
        if(digitalRead(SW)){  //********If SW is true do the following.    
           
           
           bfo = 8998500L;
           si5351.set_freq( bfo, 0, SI5351_CLK2);{
           
            if (bfo = 8998500L);
          myGLCD.setFont(BigFont);

          myGLCD.setColor(255,80,0);
          
         myGLCD.print("USB",12,61);}
           myGLCD.setColor(VGA_BLACK);
          myGLCD.print("LSB", 12, 42);
      }
      
      else{                //**********if not, do this.
          
          
          
         
          bfo = 9001500L;
          si5351.set_freq( bfo, 0, SI5351_CLK2);
             
             myGLCD.setFont(BigFont);
             myGLCD.setColor(255,80,0);
             
            myGLCD.print("LSB",12,42);
             myGLCD.setColor(VGA_BLACK);
             
            myGLCD.print("USB", 12, 61);
             
      }
      }   

    void showFreq(){
          millions = (((rx/1)-bfo)/1000000);
          hundredthousands = ((((rx/1)-bfo )/100000)%10);
          tenthousands = ((((rx/1)-bfo )/10000)%10);
          thousands = ((((rx/1)-bfo )/1000)%10);
          hundreds = ((((rx/1)-bfo )/100)%10);
          tens = ((((rx/1)-bfo )/10)%10);
          ones = ((((rx/1)-bfo )/1)%10);

         myGLCD.setFont(SevenSegNumFont);
         myGLCD.setBackColor(255,80,0);
         myGLCD.setColor(VGA_WHITE);
     
                
            myGLCD.printNumI(millions,30,91);           
            myGLCD.print("", 40,91);            
            myGLCD.printNumI(hundredthousands, 70,91);
            myGLCD.printNumI(tenthousands,100,91);
            myGLCD.printNumI(thousands,130,91);
            myGLCD.print("",140,91); //says print for the spacing
            myGLCD.printNumI(hundreds,170,91);
            myGLCD.printNumI(tens, 200,91);
            myGLCD.printNumI(ones, 230,91);
            
         
    }

           
           
     
     
     
   
      
    


          

Popular posts from this blog

November 12, 2024 Them that Know Can Make It Go!

November 18, 2024. A pair of shoes for the Hybrid SSB Transceiver.

Vote!

November 19,2024. Seven Segment Color TFT Display Fonts

2019 ~ What is the simplest homebrew SSB Transceiver that can be built?

October 26, 2024. Our democracy is at stake (Big Time). Vote wisely!