NodeMCU Center Surround Sound


NodeMCU ESP8266 ESP-12E V2 (2)
Digital Potentiometer (2)
5V Power Supply (2)
4 Dip Switch (2)
4 Slot Terminals (2)


  1. // Center Surround Sound
  2. // Speaker NodeMCU Code
  3. // pkvi
  4. #include <ESP8266WiFi.h>
  5. #include <DigiPotX9Cxxx.h>
  6. // Set Static IP Per Speaker
  7. // Ex. 20 = Center Left Speaker
  8. IPAddress ip(192, 168, 1, 20);
  9. IPAddress gateway(192, 168, 1, 1);
  10. IPAddress dns(192, 168, 1, 1);
  11. IPAddress subnet(255, 255, 255, 0);
  12. const char* ssid = "ssid";
  13. const char* pass = "password";
  14. WiFiServer server(80);
  15. // LED
  16. int led = D0;
  17. DigiPot pot(4, 5, 6);
  18. volatile int i = 0;
  19. // Start at 75%
  20. int wiper = 75;
  21. int peak = 75;
  22. // Speaker Dip Switch
  23. int dipone = 1;
  24. int diptwo = 2;
  25. void setup() {
  26. Serial.begin(115200);
  27. pinMode(dipone, INPUT);
  28. pinMode(diptwo, INPUT);
  29. if (digitalRead(dipone) == HIGH) {
  30. int dip = 1;
  31. } else if (digitalRead(diptwo) == HIGH) {
  32. int dip = 2;
  33. }
  34. pinMode(led, OUTPUT);
  35. digitalWrite(led, LOW);
  36. // Connect
  37. Serial.println(ssid);
  38. WiFi.config(ip, gateway, subnet, dns);
  39. WiFi.mode(WIFI_STA);
  40. WiFi.begin(ssid, pass);
  41. while (WiFi.status() != WL_CONNECTED) {
  42. delay(500);
  43. Serial.print(".");
  44. }
  45. Serial.println("Connected");
  46. server.begin();
  47. Serial.print("http://");
  48. Serial.print(WiFi.localIP());
  49. Serial.println("/");
  50. }
  51. void loop() {
  52. // Active LED
  53. digitalWrite(led, LOW);
  54. // Check
  55. WiFiClient client = server.available();
  56. if (!client) {
  57. return;
  58. }
  59. // Wait
  60. while (!client.available()) {
  61. delay(1);
  62. }
  63. // Read
  64. String query = client.readStringUntil('\r');
  65. client.flush();
  66. if (query.indexOf("/center") != -1) {
  67. center();
  68. }
  69. if (query.indexOf("/left_center") != -1) {
  70. left_center();
  71. }
  72. if (query.indexOf("/right_center") != -1) {
  73. right_center();
  74. }
  75. if (query.indexOf("/left_off_set") != -1) {
  76. left_off_set();
  77. }
  78. if (query.indexOf("/right_off_set") != -1) {
  79. right_off_set();
  80. }
  81. delay(1);
  82. }
  83. void center() {
  84. digitalWrite(led, HIGH);
  85. // Zero All Speakers
  86. if (wiper < peak) {
  87. for (i = wiper; i < peak; i++) {
  88. pot.increase(1);
  89. delay(5);
  90. }
  91. } else if (wiper > peak) {
  92. for (i = wiper; i > peak; i--) {
  93. pot.decrease(1);
  94. delay(5);
  95. }
  96. }
  97. }
  98. void left_center() {
  99. digitalWrite(led, HIGH);
  100. // 1 = Decrease -15
  101. // 2 = Increase +15
  102. if (dip == 1) {
  103. int lc = 60
  104. if (wiper < lc) {
  105. for (i = wiper; i < lc; i++) {
  106. pot.increase(1);
  107. delay(5);
  108. }
  109. } else if (wiper > lc) {
  110. for (i = wiper; i > lc; i--) {
  111. pot.decrease(1);
  112. delay(5);
  113. }
  114. }
  115. } else if (dip == 2) {
  116. int lc = 90
  117. if (wiper < lc) {
  118. for (i = wiper; i < lc; i++) {
  119. pot.increase(1);
  120. delay(5);
  121. }
  122. } else if (wiper > lc) {
  123. for (i = wiper; i > lc; i--) {
  124. pot.decrease(1);
  125. delay(5);
  126. }
  127. }
  128. }
  129. }
  130. void right_center() {
  131. digitalWrite(led, HIGH);
  132. // 1 = +15
  133. // 2 = -15
  134. if (dip == 1) {
  135. int lc = 90
  136. if (wiper < lc) {
  137. for (i = wiper; i < lc; i++) {
  138. pot.increase(1);
  139. delay(5);
  140. }
  141. } else if (wiper > lc) {
  142. for (i = wiper; i > lc; i--) {
  143. pot.decrease(1);
  144. delay(5);
  145. }
  146. }
  147. } else if (dip == 2) {
  148. int lc = 60
  149. if (wiper < lc) {
  150. for (i = wiper; i < lc; i++) {
  151. pot.increase(1);
  152. delay(5);
  153. }
  154. } else if (wiper > lc) {
  155. for (i = wiper; i > lc; i--) {
  156. pot.decrease(1);
  157. delay(5);
  158. }
  159. }
  160. }
  161. }
  162. void left_off_set() {
  163. digitalWrite(led, HIGH);
  164. // 1 = -25
  165. // 2 = +25
  166. if (dip == 1) {
  167. int lc = 50
  168. if (wiper < lc) {
  169. for (i = wiper; i < lc; i++) {
  170. pot.increase(1);
  171. delay(5);
  172. }
  173. } else if (wiper > lc) {
  174. for (i = wiper; i > lc; i--) {
  175. pot.decrease(1);
  176. delay(5);
  177. }
  178. }
  179. } else if (dip == 2) {
  180. int lc = 100
  181. if (wiper < lc) {
  182. for (i = wiper; i < lc; i++) {
  183. pot.increase(1);
  184. delay(5);
  185. }
  186. } else if (wiper > lc) {
  187. for (i = wiper; i > lc; i--) {
  188. pot.decrease(1);
  189. delay(5);
  190. }
  191. }
  192. }
  193. }
  194. void right_off_set() {
  195. digitalWrite(led, HIGH);
  196. // 1 = +25
  197. // 2 = -25
  198. if (dip == 1) {
  199. int lc = 100
  200. if (wiper < lc) {
  201. for (i = wiper; i < lc; i++) {
  202. pot.increase(1);
  203. delay(5);
  204. }
  205. } else if (wiper > lc) {
  206. for (i = wiper; i > lc; i--) {
  207. pot.decrease(1);
  208. delay(5);
  209. }
  210. }
  211. } else if (dip == 2) {
  212. int lc = 50
  213. if (wiper < lc) {
  214. for (i = wiper; i < lc; i++) {
  215. pot.increase(1);
  216. delay(5);
  217. }
  218. } else if (wiper > lc) {
  219. for (i = wiper; i > lc; i--) {
  220. pot.decrease(1);
  221. delay(5);
  222. }
  223. }
  224. }
  225. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
2,363 miters
123 tenons
Subscribe
0.00349