Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef UNIT_TEST
- #include <Arduino.h>
- #endif
- const String wLanHostName="8x8painter";
- #include <ESP8266WiFi.h>
- #include <DNSServer.h>
- #include <ESP8266WebServer.h>
- #include <WiFiManager.h>
- #include <ESP8266HTTPClient.h>
- ESP8266WebServer server(80);
- #include "index_html.h"
- #include <Adafruit_GFX.h>
- #include <WEMOS_Matrix_GFX.h>
- MLED matrix(7); //set intensity (7 >> maximum)
- // Feedback for Config...
- #include <Ticker.h>
- Ticker ticker;
- void tick(){
- static uint8_t state=0;
- matrix.clear();
- switch(state++){
- case 0:
- matrix.drawPixel(0,0,LED_ON);
- matrix.drawPixel(0,7,LED_ON);
- matrix.drawPixel(7,0,LED_ON);
- matrix.drawPixel(7,7,LED_ON);
- break;
- case 1:
- matrix.drawPixel(1,1,LED_ON);
- matrix.drawPixel(1,6,LED_ON);
- matrix.drawPixel(6,1,LED_ON);
- matrix.drawPixel(6,6,LED_ON);
- break;
- case 2:
- matrix.drawPixel(2,2,LED_ON);
- matrix.drawPixel(2,5,LED_ON);
- matrix.drawPixel(5,2,LED_ON);
- matrix.drawPixel(5,5,LED_ON);
- break;
- case 3:
- matrix.drawPixel(3,3,LED_ON);
- matrix.drawPixel(3,4,LED_ON);
- matrix.drawPixel(4,3,LED_ON);
- matrix.drawPixel(4,4,LED_ON);
- break;
- }
- if(state>3){
- state=0;
- }
- matrix.writeDisplay();
- }
- void updatePanel(String allLeds){
- Serial.print("Got Data: ");
- Serial.println(allLeds);
- if(allLeds.length()!=64){
- Serial.print("Data Len won't comply - try again");
- return;
- }
- matrix.clear();
- uint8_t pointer=0;
- // for(int k=7;k>=0;--k){
- for(int k=0;k<=7;k++){
- //for(int t=7;t>=0;--t){
- for(int t=0;t<=7;t++){
- if(allLeds.charAt(pointer++)=='1'){
- matrix.drawPixel(t,k,LED_ON);
- }
- }
- }
- matrix.writeDisplay();
- }
- void processIndex(){
- server.sendHeader("Cache-Control","no-cache");
- server.sendHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- if (server.args()>0){
- for (int i=0;i<server.args();i++){
- if(server.argName(i)=="data"){
- updatePanel(server.arg(i));
- }
- }
- server.send(200,"text/plain","OK");
- }else{
- server.send(200,"text/html",indexHTML);
- }
- }
- void setup(){
- Serial.begin(115200);
- delay(200);
- Serial.println("\n\n8x8 Painter --START --");
- ticker.attach(0.3,tick);
- WiFi.setOutputPower(20.5); // MAX
- WiFi.setPhyMode(WIFI_PHY_MODE_11N);
- WiFiManager wifiManager;
- // wifiManager.resetSettings();
- wifiManager.setDebugOutput(true);
- wifiManager.setAPStaticIPConfig(IPAddress(1,2,3,4),IPAddress(1,2,3,4),IPAddress(255,255,255,0));
- wifiManager.setConfigPortalTimeout(240);
- String wLANName=wLanHostName+" CONFIG";
- if(!wifiManager.autoConnect(wLANName.c_str())){
- ESP.restart();
- delay(1000);
- }
- WiFi.hostname(wLanHostName);
- Serial.print("We're connected to ");
- Serial.println(WiFi.SSID());
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- Serial.print("\nCatch me on\nhttp://");
- Serial.print(WiFi.hostname());
- Serial.print("/\n..or..\nhttp://");
- Serial.print(WiFi.localIP());
- Serial.print("/\n\n");
- server.on("/",processIndex);
- server.begin();
- matrix.clear();
- matrix.writeDisplay();
- ticker.detach();
- Serial.println("Goin into LOOP...\n");
- }
- void loop(){
- server.handleClient();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement