-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino.txt
129 lines (99 loc) · 3.55 KB
/
arduino.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#define PIN 4 // What pin is the data being sent to the Neopixels
#define NUMPIXELS 100 // How many Neopixels are you using?
#define NUM_LEDS 100
#define BRIGHTNESS 20
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800); // Set up the Neopixels strip, vital to check whether you have RGB or RGBW leds!
const char* ssid = "ilikepie"; // your wifi ssid
const char* password = "supersecure"; //your wifi password
const char* host = "tweet-my-dress.herokuapp.com"; // endpoint
String gatheredStr = "rainbow";
String prevStr ="";
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void setup() {
pixels.begin(); // Start up Neopixels
Serial.begin(115200);
delay(100);
// We start by connecting to a WiFi network
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
int value = 0;
void loop() {
delay(6000);
++value;
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/dress";
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
delay(500);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
int pos1 = line.indexOf("{") + 1;
int pos2 = line.indexOf("}");
gatheredStr = line.substring(pos1, pos2);
}
Serial.print("gathered = " + gatheredStr);
Serial.print("prev = " + prevStr);
if (gatheredStr != prevStr) {
if (gatheredStr.indexOf("rainbow") > -1) {
Serial.print("here");
uint16_t i, j;
for(j=0; j<5000; j++) {
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, Wheel((i+j) & 255));
}
pixels.show();
delay(5);
}
} else {
int commaIndex = gatheredStr.indexOf(",");
// Search for the next comma just after the first
int secondCommaIndex = gatheredStr.indexOf(",", commaIndex + 1);
String firstValue = gatheredStr.substring(0, commaIndex);
String secondValue = gatheredStr.substring(commaIndex + 1, secondCommaIndex);
String thirdValue = gatheredStr.substring(secondCommaIndex + 1); // To the end of the string
firstValue.trim();
secondValue.trim();
thirdValue.trim();
int r = firstValue.toInt();
int g = secondValue.toInt();
int b = thirdValue.toInt();
Serial.println(r);
Serial.println(g);
Serial.println(b);
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(r, b, g));
}
pixels.show(); // This sends the updated pixel color to the hardware.
delay(5000); // Delay for a period of time (in milliseconds).
}
prevStr = gatheredStr;
}
}