Arduino esp8266 wifi控制oled

Arduino esp8266 wifi控制oled
网上找的
https://hackaday.io/project/6132-esp8266oled
希望有大神可以优化。。

/*
Version 1.0 supports OLED display's with either SDD1306 or with SH1106 controller
*/

#include 
#include 
#include 
#include "font.h"
//#define offset 0x00    // SDD1306                      // offset=0 for SSD1306 controller
#define offset 0x02    // SH1106                       // offset=2 for SH1106 controller
#define OLED_address  0x3c                             // all the OLED's I have seen have this address
#define SSID "*****"                              // insert your SSID
#define PASS "****"                              // insert your password
// ******************* String form to sent to the client-browser ************************************
String form =
  "

" "

" "

Talk to me :-)

" "" "

Wassup?

" "
"; ESP8266WebServer server(80); // HTTP server will listen at port 80 long period; /* handles the messages coming from the webbrowser, restores a few special characters and constructs the strings that can be sent to the oled display */ void handle_msg() { clear_display(); // clears oled server.send(200, "text/html", form); // Send same page so they can send another msg // Display msg on Oled String msg = server.arg("msg"); Serial.println(msg); String decodedMsg = msg; // Restore special characters that are misformed to %char by the client browser decodedMsg.replace("+", " "); decodedMsg.replace("%21", "!"); decodedMsg.replace("%22", ""); decodedMsg.replace("%23", "#"); decodedMsg.replace("%24", "$"); decodedMsg.replace("%25", "%"); decodedMsg.replace("%26", "&"); decodedMsg.replace("%27", "'"); decodedMsg.replace("%28", "("); decodedMsg.replace("%29", ")"); decodedMsg.replace("%2A", "*"); decodedMsg.replace("%2B", "+"); decodedMsg.replace("%2C", ","); decodedMsg.replace("%2F", "/"); decodedMsg.replace("%3A", ":"); decodedMsg.replace("%3B", ";"); decodedMsg.replace("%3C", "<"); decodedMsg.replace("%3D", "="); decodedMsg.replace("%3E", ">"); decodedMsg.replace("%3F", "?"); decodedMsg.replace("%40", "@"); //Serial.println(decodedMsg); // print original string to monitor unsigned int lengte = decodedMsg.length(); // length of received message for (int i=0;i>4)&0x0f)); //set high col address } //==========================================================// // Prints a string regardless the cursor position. static void sendStr(unsigned char *string) { unsigned char i=0; while(*string) { for(i=0;i<8;i++) { SendChar(pgm_read_byte(myFont[*string-0x20]+i)); } *string++; } } //==========================================================// // Prints a string in coordinates X Y, being multiples of 8. // This means we have 16 COLS (0-15) and 8 ROWS (0-7). static void sendStrXY( const char *string, int X, int Y) { setXY(X,Y); unsigned char i=0; while(*string) { for(i=0;i<8;i++) { SendChar(pgm_read_byte(myFont[*string-0x20]+i)); } *string++; } } //==========================================================// // Inits oled and draws logo at startup static void init_OLED(void) { sendcommand(0xae); //display off sendcommand(0xa6); //Set Normal Display (default) // Adafruit Init sequence for 128x64 OLED module sendcommand(0xAE); //DISPLAYOFF sendcommand(0xD5); //SETDISPLAYCLOCKDIV sendcommand(0x80); // the suggested ratio 0x80 sendcommand(0xA8); //SSD1306_SETMULTIPLEX sendcommand(0x3F); sendcommand(0xD3); //SETDISPLAYOFFSET sendcommand(0x0); //no offset sendcommand(0x40 | 0x0); //SETSTARTLINE sendcommand(0x8D); //CHARGEPUMP sendcommand(0x14); sendcommand(0x20); //MEMORYMODE sendcommand(0x00); //0x0 act like ks0108 //sendcommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg sendcommand(0xA0); //sendcommand(0xC8); //COMSCANDEC Rotate screen 180 Deg sendcommand(0xC0); sendcommand(0xDA); //0xDA sendcommand(0x12); //COMSCANDEC sendcommand(0x81); //SETCONTRAS sendcommand(0xCF); // sendcommand(0xd9); //SETPRECHARGE sendcommand(0xF1); sendcommand(0xDB); //SETVCOMDETECT sendcommand(0x40); sendcommand(0xA4); //DISPLAYALLON_RESUME sendcommand(0xA6); //NORMALDISPLAY clear_display(); sendcommand(0x2e); // stop scroll //----------------------------REVERSE comments----------------------------// sendcommand(0xa0); //seg re-map 0->127(default) sendcommand(0xa1); //seg re-map 127->0 sendcommand(0xc8); delay(1000); //----------------------------REVERSE comments----------------------------// // sendcommand(0xa7); //Set Inverse Display // sendcommand(0xae); //display off sendcommand(0x20); //Set Memory Addressing Mode sendcommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode // sendcommand(0x02); // Set Memory Addressing Mode ab Page addressing mode(RESET) }

你可能感兴趣的:(Arduino esp8266 wifi控制oled)