Advertisement
pleasedontcode

"Radio Frequency Display" rev_01

Mar 15th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Radio Frequency Display"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-03-15 11:13:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* USB Connection to Kenwood TS-590SG radio.  Read */
  21.     /* radio operating frequency from radio Serial Data */
  22.     /* (115200 BAUD) Decide which Amateur radio Frequency */
  23.     /* Band the radio's frequency is on, write radio */
  24.     /* frequency and frequency Band to LCD Display */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Wire.h>
  29. #include <LiquidCrystal_I2C.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /******* SYSTEM REQUIREMENTS *******/
  36. /****** SYSTEM REQUIREMENT 1 *****/
  37. /* USB Connection to Kenwood TS-590SG radio. Read */
  38. /* radio operating frequency from radio Serial Data */
  39. /* (115200 BAUD) Decide which Amateur radio Frequency */
  40. /* Band the radio's frequency is on, write radio */
  41. /* frequency and frequency Band to LCD Display */
  42. /************************************/
  43.  
  44. /***** DEFINITION OF I2C PINS *****/
  45. const uint8_t LCD1602i2c_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  46. const uint8_t LCD1602i2c_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  47. const uint8_t LCD1602i2c_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27;
  48.  
  49. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  50. LiquidCrystal_I2C lcd(LCD1602i2c_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4); // Initialize the LiquidCrystal_I2C object
  51.  
  52. void setup(void)
  53. {
  54.   // put your setup code here, to run once:
  55.   lcd.begin(20, 4); // Initialize the LCD with 20 columns and 4 rows
  56.   lcd.backlight(); // Turn on the backlight
  57.   Serial.begin(115200); // Initialize the Serial communication with the radio
  58. }
  59.  
  60. void loop(void)
  61. {
  62.   // put your main code here, to run repeatedly:
  63.   if (Serial.available())
  64.   {
  65.     delay(100);
  66.     lcd.clear(); // Clear the LCD screen
  67.    
  68.     // Read the radio operating frequency from the Serial data
  69.     float frequency = Serial.parseFloat();
  70.     lcd.print("Frequency: ");
  71.     lcd.print(frequency, 1); // Print the frequency with 1 decimal place
  72.    
  73.     // Decide which Amateur radio Frequency Band the radio's frequency is on
  74.     String frequencyBand = "";
  75.     if (frequency >= 1.8 && frequency <= 2.0) {
  76.       frequencyBand = "160m";
  77.     } else if (frequency >= 3.5 && frequency <= 4.0) {
  78.       frequencyBand = "80m";
  79.     } else if (frequency >= 7.0 && frequency <= 7.3) {
  80.       frequencyBand = "40m";
  81.     } else if (frequency >= 14.0 && frequency <= 14.35) {
  82.       frequencyBand = "20m";
  83.     } else if (frequency >= 21.0 && frequency <= 21.45) {
  84.       frequencyBand = "15m";
  85.     } else if (frequency >= 28.0 && frequency <= 29.7) {
  86.       frequencyBand = "10m";
  87.     } else {
  88.       frequencyBand = "Unknown Band";
  89.     }
  90.    
  91.     // Write the radio frequency and frequency band to the LCD display
  92.     lcd.setCursor(0, 1);
  93.     lcd.print("Band: ");
  94.     lcd.print(frequencyBand);
  95.   }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement