Guest User

Radio Header

a guest
Jul 27th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. /*
  2. Connections:
  3. Rotary Encoder:
  4. + -> 3.3v
  5. GND -> GND
  6. SW -> D32
  7. DT -> D34
  8. CLK -> D35
  9. OLD:
  10. SW -> D13
  11. DT -> D27
  12. CLK -> D14
  13. Amplifier/Speakers:
  14. LRC -> D25 (Both amps connected)
  15. BCLK -> D26 (Both amps connected)
  16. Din -> D22 (Both amps connected)
  17. Gain -> will use this later
  18. SD -> D33 (Left amp only! Connect from GPIO to right amp through resistors)
  19. GND -> GND
  20. VIN -> Din (5v)
  21. RGB LED:
  22. Red -> D14
  23. Green -> D13
  24. Blue -> D12
  25. SD Card:
  26. 3V3 -> 3.3v
  27. CS -> D5
  28. MOSI -> D23
  29. CLK -> D18
  30. MISO -> D19
  31. GND -> GND
  32.  
  33. */
  34.  
  35. #include "AudioTools.h"
  36. #include "AudioTools/AudioLibs/AudioSourceSD.h"
  37. #include "AudioTools/AudioCodecs/CodecMP3Helix.h"
  38.  
  39. // Bluetooth Libraries==============================================================
  40. #include <ESP_I2S.h>
  41. #include <wav_header.h>
  42. #include "BluetoothA2DPSink.h"
  43.  
  44. // Rotary Encoder Button Library (might not use this)===============================
  45. #include <BfButton.h>
  46.  
  47. // RGB LEDs=========================================================================
  48. #define LED_red 14
  49. #define LED_green 13
  50. #define LED_blue 12
  51.  
  52. // SD card Library and defines======================================================
  53. #include <SD.h>
  54. #define SD_sck 18
  55. #define SD_miso 19
  56. #define SD_mosi 23
  57. #define SD_cs 5
  58.  
  59. I2SStream i2s;
  60. I2SStream i2s_NoOutput;
  61.  
  62. auto SDConfig = i2s.defaultConfig(TX_MODE);
  63. auto BTConfig = i2s.defaultConfig(TX_MODE);
  64.  
  65. AudioInfo BlueToothAudioInfo(44100, 2, 24);
  66.  
  67. // =====SDCard Variables=====:
  68. const char *startFilePath="/";
  69. const char* ext="mp3";
  70. AudioSourceSD source(startFilePath, ext);
  71. MP3DecoderHelix decoder;
  72. AudioPlayer player(source, i2s, decoder);
  73.  
  74. BluetoothA2DPSink a2dp_sink(i2s);
  75.  
  76. // Other Libraries==================================================================
  77. #include <string>
  78. #include <cstdint>
  79.  
  80. int RE_DT = 34;
  81. int RE_CLK = 35;
  82. int RE_Button = 32;
  83. int max_RE_Value = 98;
  84. int min_RE_Value = 0;
  85. BfButton btn(BfButton::STANDALONE_DIGITAL, RE_Button, true, LOW);
  86.  
  87. int counter = 0;
  88. int aState;
  89. int aLastState;
  90. int reading = 0;
  91. uint32_t runTime = -99999;
  92.  
  93. enum playbackMode
  94. {
  95. initBluetooth,
  96. bluetoothMode,
  97. deInitBluetooth,
  98. initSDCard,
  99. SDcardMode,
  100. deInitSDCard
  101. };
  102.  
  103. playbackMode currentState = initBluetooth; // This determines what mode we start in and is a global to maintain state;
  104.  
  105. // Function Prototypes =============================================================
  106.  
  107. void handleBluetooth();
  108.  
  109. void handleSDcard();
  110.  
  111. void avrc_metadata_callback(uint8_t data1, const uint8_t *data2);
  112.  
  113. void parseBluetoothData(uint8_t address, const uint8_t *data);
  114.  
  115. void pressHandler (BfButton *btn, BfButton::press_pattern_t pattern);
  116.  
  117. void printMetaData(MetaDataType type, const char* str, int len);
Advertisement
Add Comment
Please, Sign In to add comment