-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweetMatrix.ino
144 lines (108 loc) · 3.04 KB
/
TweetMatrix.ino
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <ESP8266WiFi.h>
#include <FastLED.h>
#include <LEDMatrix.h>
#include <LEDText.h>
#include <FontMatrise.h>
//ESP stuff
const char* ssid = "CaseGuest";
const char* password = "";
const char* host = "api.thingspeak.com";
String tweet = "";
// Change the next 6 defines to match your matrix type and size
#define LED_PIN 6
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define MATRIX_WIDTH 10
#define MATRIX_HEIGHT 10
#define MATRIX_TYPE HORIZONTAL_ZIGZAG_MATRIX
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
cLEDText ScrollingMsg;
const unsigned char TxtDemo[] = { EFFECT_FRAME_RATE "\x04" EFFECT_SCROLL_LEFT tweet(String)};
void setup()
{
Serial.begin(9600);
delay(1000);
//wifi connection stuff
Serial.println();
Serial.println();
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");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
FastLED.setBrightness(100);
FastLED.clear(true);
delay(500);
FastLED.showColor(CRGB::Red);
delay(1000);
FastLED.showColor(CRGB::Lime);
delay(1000);
FastLED.showColor(CRGB::Blue);
delay(1000);
FastLED.showColor(CRGB::White);
delay(1000);
FastLED.show();
ScrollingMsg.SetFont(MatriseFontData);
ScrollingMsg.Init(&leds, leds.Width(), ScrollingMsg.FontHeight() + 1, 0, 0);
ScrollingMsg.SetText((unsigned char *)TxtDemo, sizeof(TxtDemo) - 1);
ScrollingMsg.SetTextColrOptions(COLR_RGB | COLR_SINGLE, 0xff, 0x00, 0xff);
}
void loop()
{
getTweet();
for(int x=0;x<100;x++)
{
if (ScrollingMsg.UpdateText() == -1)
ScrollingMsg.SetText((unsigned char *)TxtDemo, sizeof(TxtDemo) - 1);
else
FastLED.show();
delay(10);
}
Serial.println("hey");
delay(10000);
}
void getTweet()
{
delay(1000);
Serial.print("connecting to ");
Serial.println(host);
// 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 = "/channels/225462/fields/1/last.txt";
Serial.print("Requesting URL: ");
Serial.println(url);
// 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
int x = 0;
while(client.available())
{
String line = client.readStringUntil('\r');
if(x == 19)
{
Serial.println(line.substring(21));
tweet = line;
}
//String line = client.readStringUntil('\r');
//Serial.println(line + "LineNumber: " + x);
x++;
}
Serial.println();
Serial.println("closing connection");
}