Skip to content

Instantly share code, notes, and snippets.

@shunkino
Created July 18, 2015 10:18
Show Gist options
  • Save shunkino/1e492ff752e690df245f to your computer and use it in GitHub Desktop.
Save shunkino/1e492ff752e690df245f to your computer and use it in GitHub Desktop.
ESP+2.4 LED
#include <doxygen.h>
#include <ESP8266.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library 機種依存のライブラリ
//ESP用のマクロ
#define SSID "your_SSID"
#define PASSWORD "your_key"
#define HOST_NAME "your_host_name"
#define HOST_PORT (host_port)
//ピンアサインメントのためのマクロ
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin リセット
//色をわかりやすく表記するためのマクロ
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xF944
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
float divergence = 1.048596;
//String data;
char *hello = "GET /card HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
ESP8266 wifi(Serial);
void setup() {
Serial.begin(9600);
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(1);
// ここで描画メソッドを呼び出す。
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
// tft.print(data);
// tft.println(wifi.getVersion().c_str());
setupConnection();
// testText();
connectTCP();
sendRequest();
}
void loop() {
// updateText();
while (Serial.available() > 0) {
char character = Serial.read();
tft.print(character);
if(character == '>') {
tft.fillScreen(BLACK);
tft.setCursor(0, 0);
Serial.print(hello);
}
// data += character;
}
}
void setupConnection() {
if (wifi.setOprToStationSoftAP()) {
tft.print(F("to station + softap ok\r\n"));
} else {
tft.print(F("to station + softap err\r\n"));
}
if (wifi.joinAP(SSID, PASSWORD)) {
tft.print(F("Join AP success\r\n"));
tft.println(F("IP:"));
tft.println( wifi.getLocalIP().c_str());
} else {
tft.println("Join AP failure\r\n");
}
if (wifi.disableMUX()) {
tft.print(F("single ok\r\n"));
} else {
tft.print("single err\r\n");
}
tft.print("setup end\r\n");
}
void connectTCP() {
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
tft.print("create tcp ok\r\n");
} else {
tft.print("create tcp err\r\n");
}
}
void sendRequest() {
// uint8_t buffer[1024] = {0};
// tft.print(hello);
//以下の文字列を、SerialでのHTTP通信の前に予め送っておく
Serial.print(F("AT+CIPSEND="));
Serial.println(strlen(hello));
// tft.println(data);
//
// wifi.send((const uint8_t*)hello, strlen(hello));
// uint32_t len = wifi.recv(buffer, sizeof(buffer));
// if (len > 0) {
// tft.print("Received:[");
// for (uint32_t i = 0; i < len; i++) {
// tft.print((char)buffer[i]);
// }
// tft.println("]\r\n");
// closeTCP();
// }
}
void closeTCP() {
if (wifi.releaseTCP()) {
tft.println("release tcp ok\r\n");
} else {
tft.println("release tcp err\r\n");
}
}
void testText() {
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.println(F("TEST"));
tft.println(F("LCD EDITION"));
tft.println(F("Developed by FUTURE GADGET LABORATORY"));
updateText();
// tft.setCursor(80, 100);
// tft.setTextColor(ORANGE);
// tft.setTextSize(4);
// tft.setTextWrap(true);
// tft.println(divergence, 6);
// tft.setCursor(0, 0);
}
void updateText() {
tft.fillRect(80, 100, 240, 50, BLACK);
tft.setCursor(80, 100);
tft.setTextColor(ORANGE);
tft.setTextSize(4);
tft.setTextWrap(true);
tft.println(divergence, 6);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment