Skip to content

Instantly share code, notes, and snippets.

@yusuke
Created December 30, 2017 13:38
Show Gist options
  • Save yusuke/f1e78ad04c12878e0b22fd8df90a9052 to your computer and use it in GitHub Desktop.
Save yusuke/f1e78ad04c12878e0b22fd8df90a9052 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include "esp_system.h"
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#define USE_SERIAL Serial
WiFiMulti wifiMulti;
HTTPClient http;
int area = 123;
int yagura = 100;
int hoko = 83;
int asari = 70;
int neutral = 26;
int angles[] = {area, yagura, hoko, asari, neutral};
int lastAngle = 26;
void setup() {
ledcSetup(0, 50, 10); // 0ch 50 Hz 10bit resolution
ledcAttachPin(15, 0); // 15pin, 0ch
// 初期値に移動
ledcWrite(0, lastAngle);
USE_SERIAL.begin(115200);
wifiMulti.addAP("ssid", "password");
wifiMulti.addAP("ssid2", "password2");
wifiMulti.addAP("ssid3", "password3");
http.setReuse(true);
}
void loop() {
if((wifiMulti.run() == WL_CONNECTED)) {
http.begin("http://35.200.37.169/gachi.txt");
int httpCode = http.GET();
if(httpCode > 0 && httpCode == HTTP_CODE_OK) {
String rules = http.getString();
byte zero = '0';
int angle = angles[rules.charAt(0)-zero];
if(angle != lastAngle){
Serial.println(angle);
ledcWrite(0, angle);
lastAngle = angle;
}
}
http.end();
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment