Advertisement
pleasedontcode

Audio Control rev_01

Oct 15th, 2024
77
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: Audio Control
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-15 20:52:09
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* use TFT ILI9488 SPI and PT2314 chip for audio int */
  21.     /* vol,bass,treble,gain,loudness,mute,attnR,attnL */
  22.     /* channel,bal_l,bal_r menu,options update display */
  23.     /* rotar values */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SimpleEncoder.h>  // Library for rotary encoder
  28. #include <TFT_eSPI.h>       // TFT library for ILI9488 display
  29. #include <PT2314.h>         // Library for PT2314 audio processor
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t ro_KY_040_CLK_PIN_D4 = 4;    // Rotary encoder CLK pin
  37. const uint8_t ro_KY_040_DT_PIN_D13 = 13;   // Rotary encoder DT pin
  38. const uint8_t ro_KY_040_SW_PIN_D14 = 14;   // Rotary encoder switch pin
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  41. SimpleEncoder encoder(ro_KY_040_SW_PIN_D14, ro_KY_040_CLK_PIN_D4, ro_KY_040_DT_PIN_D13); // Encoder instance
  42. TFT_eSPI tft = TFT_eSPI(); // TFT display instance
  43. PT2314 audioProcessor; // PT2314 audio processor instance
  44.  
  45. void setup(void)
  46. {
  47.     // Initialize serial communication for debugging
  48.     Serial.begin(9600);
  49.  
  50.     // Initialize the TFT display
  51.     tft.init();
  52.     tft.setRotation(1); // Set rotation of the display
  53.     tft.fillScreen(TFT_BLACK); // Clear screen with black color
  54.  
  55.     // Initialize the audio processor
  56.     if (audioProcessor.begin()) {
  57.         Serial.println("PT2314 initialized successfully.");
  58.     } else {
  59.         Serial.println("Failed to initialize PT2314.");
  60.     }
  61.  
  62.     // Set initial audio settings
  63.     audioProcessor.setVolume(30); // Set initial volume
  64.     audioProcessor.setBass(0);     // Set initial bass
  65.     audioProcessor.setTreble(0);   // Set initial treble
  66.     audioProcessor.setMute(false);  // Unmute audio
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // Check if the encoder value is changing
  72.     if (encoder.CHANGING) {
  73.         // Get the current value from the encoder
  74.         int value = encoder.VALUE;
  75.  
  76.         // Update audio settings based on encoder value
  77.         if (value >= 0 && value <= 63) {
  78.             audioProcessor.setVolume(value); // Set volume based on encoder value
  79.             Serial.print("Volume set to: ");
  80.             Serial.println(value);
  81.         } else if (value > 63 && value <= 127) {
  82.             audioProcessor.setBass(value - 64); // Set bass if value exceeds 63
  83.             Serial.print("Bass set to: ");
  84.             Serial.println(value - 64);
  85.         } else if (value < 0 && value >= -63) {
  86.             audioProcessor.setTreble(-value); // Set treble if value is negative
  87.             Serial.print("Treble set to: ");
  88.             Serial.println(-value);
  89.         }
  90.  
  91.         // Update the display with the current settings
  92.         tft.setTextColor(TFT_WHITE);
  93.         tft.setTextSize(2);
  94.         tft.setCursor(10, 10);
  95.         tft.printf("Volume: %d\nBass: %d\nTreble: %d\n", audioProcessor.getVolume(), audioProcessor.getBass(), audioProcessor.getTreble());
  96.     }
  97. }
  98.  
  99. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement