Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Audio Control
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-10-15 21:08:40
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* use TFT ILI9488 SPI and PT2314 chip for audio int */
- /* vol,bass,treble,gain,loudness,mute,attnR,attnL */
- /* channel,bal_l,bal_r menu,options update display */
- /* rotar values */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - add Ticker.h for ms,menu cases display draw menu0-4 add menu set
- tings ,audio,clock, rotary handle volume ,bass,treble,gain,loud,
- mute,in,i,bal_l,bal_r
- ********* User code review feedback **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SimpleEncoder.h> // Library for rotary encoder
- #include <TFT_eSPI.h> // TFT library for ILI9488 display
- #include <PT2314.h> // Library for PT2314 audio processor
- #include <Ticker.h> // Library for timing events
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Menu states
- enum MenuState {
- MENU_MAIN,
- MENU_SETTINGS,
- MENU_AUDIO,
- MENU_CLOCK,
- MENU_EXIT
- };
- // Current menu state
- MenuState currentMenu = MENU_MAIN;
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t ro_KY_040_CLK_PIN_D4 = 4; // Rotary encoder CLK pin
- const uint8_t ro_KY_040_DT_PIN_D13 = 13; // Rotary encoder DT pin
- const uint8_t ro_KY_040_SW_PIN_D14 = 14; // Rotary encoder switch pin
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- SimpleEncoder encoder(ro_KY_040_SW_PIN_D14, ro_KY_040_CLK_PIN_D4, ro_KY_040_DT_PIN_D13); // Encoder instance
- TFT_eSPI tft = TFT_eSPI(); // TFT display instance
- PT2314 audioProcessor; // PT2314 audio processor instance
- Ticker ticker; // Ticker instance for periodic tasks
- // Audio settings variables
- int volume = 30;
- int bass = 0;
- int treble = 0;
- int gain = 0;
- bool loudness = false;
- bool mute = false;
- // Function to draw the main menu
- void drawMenu() {
- tft.fillScreen(TFT_BLACK); // Clear screen
- tft.setTextColor(TFT_WHITE);
- tft.setTextSize(2);
- tft.setCursor(10, 10);
- switch (currentMenu) {
- case MENU_MAIN:
- tft.println("Main Menu");
- tft.println("1. Settings");
- tft.println("2. Audio");
- tft.println("3. Clock");
- tft.println("4. Exit");
- break;
- case MENU_SETTINGS:
- tft.println("Settings Menu");
- tft.println("Adjust settings");
- break;
- case MENU_AUDIO:
- tft.println("Audio Menu");
- tft.printf("Volume: %d\nBass: %d\nTreble: %d\n", volume, bass, treble);
- break;
- case MENU_CLOCK:
- tft.println("Clock Menu");
- tft.println("Set the time");
- break;
- case MENU_EXIT:
- tft.println("Exiting...");
- break;
- }
- }
- // Function to update audio settings based on encoder value
- void updateAudioSettings(int value) {
- if (value >= 0 && value <= 63) {
- audioProcessor.setVolume(value); // Set volume based on encoder value
- volume = value; // Update local variable
- } else if (value > 63 && value <= 127) {
- audioProcessor.setBass(value - 64); // Set bass if value exceeds 63
- bass = value - 64; // Update local variable
- } else if (value < 0 && value >= -63) {
- audioProcessor.setTreble(-value); // Set treble if value is negative
- treble = -value; // Update local variable
- }
- }
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- // Initialize the TFT display
- tft.init();
- tft.setRotation(1); // Set rotation of the display
- tft.fillScreen(TFT_BLACK); // Clear screen with black color
- // Initialize the audio processor
- if (audioProcessor.begin()) {
- Serial.println("PT2314 initialized successfully.");
- } else {
- Serial.println("Failed to initialize PT2314.");
- }
- // Set initial audio settings
- audioProcessor.setVolume(volume); // Set initial volume
- audioProcessor.setBass(bass); // Set initial bass
- audioProcessor.setTreble(treble); // Set initial treble
- audioProcessor.setMute(mute); // Unmute audio
- // Draw the initial menu
- drawMenu();
- }
- void loop(void)
- {
- // Check if the encoder value is changing
- if (encoder.CHANGING) {
- // Get the current value from the encoder
- int value = encoder.VALUE;
- // Update audio settings based on encoder value
- updateAudioSettings(value);
- // Update the display with the current settings
- drawMenu();
- }
- // Handle menu navigation
- if (encoder.BUTTON_PRESSED) {
- // Change menu state based on current state
- switch (currentMenu) {
- case MENU_MAIN:
- currentMenu = MENU_SETTINGS; // Go to settings menu
- break;
- case MENU_SETTINGS:
- currentMenu = MENU_AUDIO; // Go to audio menu
- break;
- case MENU_AUDIO:
- currentMenu = MENU_CLOCK; // Go to clock menu
- break;
- case MENU_CLOCK:
- currentMenu = MENU_EXIT; // Go to exit menu
- break;
- case MENU_EXIT:
- currentMenu = MENU_MAIN; // Return to main menu
- break;
- }
- drawMenu(); // Redraw the menu
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement