PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 satır
5.4KB

  1. #include <Artnet.h>
  2. #include <SPI.h>
  3. #include <Wire.h>
  4. #include <Adafruit_GFX.h>
  5. #include <Adafruit_SSD1306.h>
  6. #include <Adafruit_FeatherOLED.h>
  7. #include <Adafruit_FeatherOLED_WiFi.h>
  8. #include <Adafruit_NeoPixel.h>
  9. //Neopixels
  10. const int numLeds = 64;
  11. const int numberOfChannels = numLeds * 3;
  12. const byte dataPin = 12;
  13. Adafruit_NeoPixel leds = Adafruit_NeoPixel(numLeds, dataPin, NEO_GRB + NEO_KHZ800);
  14. #include <WiFi101.h>
  15. #include <WiFiUdp.h>
  16. #define VBAT_ENABLED 1
  17. #define VBAT_PIN A7
  18. #define FEED_VBAT "vbat"
  19. int status = WL_IDLE_STATUS;
  20. char ssid[] = "R&D_wifi"; // your network SSID (name)
  21. char pass[] = "erede2K16"; // your network password (use for WPA, or use as key for WEP)
  22. Artnet artnet;
  23. Adafruit_FeatherOLED_WiFi oled = Adafruit_FeatherOLED_WiFi();
  24. #if (SSD1306_LCDHEIGHT != 32)
  25. #error ("Height incorrect, please fix Adafruit_SSD1306.h!");
  26. #endif
  27. void setup() {
  28. Serial.begin(9600);
  29. WiFi.setPins(8,7,4,2);
  30. leds.begin();
  31. initTest();
  32. Serial.println("OLED FeatherWing test");
  33. oled.init();
  34. oled.clearDisplay();
  35. pinMode(VBAT_PIN, INPUT);
  36. oled.setBatteryIcon(true);
  37. updateVbat();
  38. oled.refreshIcons();
  39. oled.clearMsgArea();
  40. oled.println("Connecting to ...");
  41. oled.println(ssid);
  42. // oled.display();
  43. // while (!Serial) {
  44. // ; // wait for serial port to connect. Needed for native USB port only
  45. // }
  46. // check for the presence of the shield:
  47. if (WiFi.status() == WL_NO_SHIELD) {
  48. Serial.println("WiFi shield not present");
  49. // don't continue:
  50. while (true) ;
  51. }
  52. // attempt to connect to Wifi network:
  53. while ( status != WL_CONNECTED) {
  54. Serial.print("Attempting to connect to SSID: ");
  55. Serial.println(ssid);
  56. // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  57. status = WiFi.begin(ssid, pass);
  58. // wait 10 seconds for connection:
  59. delay(10000);
  60. }
  61. Serial.println("Connected to wifi");
  62. printWifiStatus();
  63. artnet.begin();
  64. artnet.setArtDmxCallback(onDmxFrame);
  65. Serial.println("\nStarting connection to server...");
  66. //Udp.begin(localPort);
  67. delay(1000);
  68. }
  69. void loop() {
  70. artnet.read();
  71. // if ( VBAT_ENABLED )
  72. // updateVbat();
  73. //long rssi = WiFi.RSSI();
  74. // oled.setRSSI(rssi);
  75. // oled.refreshIcons();
  76. // oled.display();
  77. }
  78. void printWifiStatus() {
  79. // print the SSID of the network you're attached to:
  80. Serial.print("SSID: ");
  81. Serial.println(WiFi.SSID());
  82. // print your WiFi shield's IP address:
  83. IPAddress ip = WiFi.localIP();
  84. Serial.print("IP Address: ");
  85. Serial.println(ip);
  86. // print the received signal strength:
  87. long rssi = WiFi.RSSI();
  88. Serial.print("signal strength (RSSI):");
  89. Serial.print(rssi);
  90. Serial.println(" dBm");
  91. oled.setConnected(true);
  92. oled.setRSSI(rssi);
  93. oled.setIPAddress(ip);
  94. oled.refreshIcons();
  95. oled.clearMsgArea();
  96. // oled.display();
  97. }
  98. void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
  99. {
  100. // print out our data
  101. Serial.print("universe number = ");
  102. Serial.print(universe);
  103. Serial.print("\tdata length = ");
  104. Serial.print(length);
  105. Serial.print("\tsequence n0. = ");
  106. Serial.println(sequence);
  107. Serial.print("DMX data: ");
  108. for (int i = 0; i < length; i++)
  109. {
  110. Serial.print(data[i]);
  111. Serial.print(" ");
  112. }
  113. Serial.println();
  114. Serial.println();
  115. for (int i = 0; i < (length / 3); i++) {
  116. leds.setPixelColor(i, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
  117. }
  118. leds.show();
  119. // oled.clearMsgArea();
  120. // oled.print("Universe: ");
  121. // oled.println(universe);
  122. // for (int i = 0; i < length ; i++) {
  123. // if (i < 5) {
  124. // oled.print(data[i]);
  125. // oled.print(" ");
  126. // }
  127. // }
  128. // oled.display();
  129. }
  130. void updateVbat()
  131. {
  132. int vbatADC = 0; // The raw ADC value off the voltage div
  133. float vbatFloat = 0.0F; // The ADC equivalent in millivolts
  134. float vbatLSB = 0.80566F;// mV per LSB
  135. // Read the analog in value:
  136. vbatADC = analogRead(VBAT_PIN);
  137. vbatADC = analogRead(VBAT_PIN);
  138. // Multiply the ADC by mV per LSB, and then
  139. // double the output to compensate for the
  140. // 10K+10K voltage divider
  141. vbatFloat = ((float)vbatADC * vbatLSB) * 2.0F;
  142. oled.setBattery(vbatFloat/1000);
  143. }
  144. void initTest()
  145. {
  146. for (int i = 0; i < numLeds; i++)
  147. leds.setPixelColor(i, 127, 0, 0);
  148. leds.show();
  149. delay(500);
  150. for (int i = 0; i < numLeds; i++)
  151. leds.setPixelColor(i, 0, 127, 0);
  152. leds.show();
  153. delay(500);
  154. for (int i = 0; i < numLeds; i++)
  155. leds.setPixelColor(i, 0, 0, 127);
  156. leds.show();
  157. delay(500);
  158. for (int i = 0; i < numLeds; i++)
  159. leds.setPixelColor(i, 0, 0, 0);
  160. leds.show();
  161. }