Skip to content

Commit c4f99ff

Browse files
committed
added some comments
1 parent 6623f4b commit c4f99ff

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

Twitter_fade_lamp/Twitter_fade_lamp.ino

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,49 @@
1+
/*
2+
Twitter Lamp demo sketch: monitors one or more Twitter accounts
3+
for changes, changing the RGB led colors
4+
Based on the orginal code of Gutenbird by Adafruit Industries
5+
Modified by Federico Vanzati (Officine Arduino)
6+
Released with MIT licesne.
7+
8+
REQUIRES ARDUINO IDE 1.0 OR LATER -- Back-porting is not likely to
9+
occur, as the code is deeply dependent on the Stream class, etc.
10+
11+
Required hardware includes a WiFi Shield connected to the Arduino UNO board
12+
and power RGB leds.
13+
*/
14+
115
#include <SPI.h>
216
#include <WiFi.h>
317
#include "structRgb.h"
418
#include <avr/pgmspace.h>
519

6-
char *queryString1 = "#news";
7-
char *queryString2 = "#arduino";
20+
// Enter your hashtag that you want to monitoring
21+
char *queryString1 = "#yourhashtag"; // first hashtag
22+
char *queryString2 = "#arduino"; // second hashtag
823

9-
char ssid[] = "OFFICINE ARDUINO"; // your network SSID (name)
24+
// Enter your WiFi network settings
25+
char ssid[] = "yourSSID"; // your network SSID (name)
1026
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
1127
int keyIndex = 0; // your network key Index number (needed only for WEP)
1228
int status = WL_IDLE_STATUS; // status of the wifi connection
1329

1430

15-
const int pin_r = 5;
16-
const int pin_g = 6;
17-
const int pin_b = 3;
31+
const int pin_r = 5; // pwm pin for the red led
32+
const int pin_g = 6; // pwm pin for the green led
33+
const int pin_b = 3; // pwm pin for the blue led
1834

19-
const uint8_t mode1_switch = 2;
20-
const uint8_t mode2_switch = 8;
35+
const uint8_t mode1_switch = 2; // pin where connect the switch for mode 1
36+
const uint8_t mode2_switch = 8; // pin where connect the switch for mode 2
2137
uint8_t prev_mode1Switch = true;
2238
uint8_t prev_mode2Switch = true;
2339

24-
const int maxTweets = 5; // Limit tweets printed; avoid runaway output
40+
const int maxTweets = 5; // Limit tweets printed; avoid runaway output
2541

2642
const unsigned long // Time limits, expressed in milliseconds:
2743
pollingInterval = 10L * 1000L, // Note: Twitter server will allow 150/hr max
2844
connectTimeout = 15L * 1000L, // Max time to retry server link
29-
responseTimeout = 15L * 1000L, // Max time to wait for data from server
30-
fadeInterval = 1000;
31-
32-
unsigned long prevMillisFade = 0;
45+
responseTimeout = 15L * 1000L; // Max time to wait for data from server
3346

34-
byte sleepPos = 0; // Current "sleep throb" table position
3547
byte resultsDepth; // Used in JSON parsing
3648

3749
uint8_t colorCount = 0;
@@ -71,10 +83,10 @@ fadeTo(rgb, rgb);
7183
// ---------------------------------------------------------------------------
7284

7385
void setup() {
74-
pinMode(mode1_switch, INPUT_PULLUP);
75-
pinMode(mode2_switch, INPUT_PULLUP);
76-
86+
pinMode(mode1_switch, INPUT_PULLUP); // connecting the first pin directly to the input pin w/o external hardware
87+
pinMode(mode2_switch, INPUT_PULLUP); // connecting the second pin directly to the input pin w/o external hardware
7788

89+
// Little test just to check if the the leds are working and saying hello
7890
analogWrite(pin_r, 255);
7991
analogWrite(pin_g, 0);
8092
analogWrite(pin_b, 0);
@@ -94,6 +106,7 @@ void setup() {
94106
analogWrite(pin_g, 0);
95107
analogWrite(pin_b, 0);
96108

109+
// Initialize the serial communication, used only for debuggging
97110
Serial.begin(9600);
98111

99112
// check for the presence of the shield:
@@ -111,7 +124,7 @@ void setup() {
111124
status = WiFi.begin(ssid, pass);
112125

113126
// wait 10 seconds for connection:
114-
delay(5000);
127+
delay(10000);
115128
}
116129
// you're connected now, so print out the status:
117130
printWifiStatus();
@@ -134,11 +147,12 @@ void loop() {
134147

135148
startTime = millis();
136149

150+
// check the switch state
137151
uint8_t mode1_switchStatus = digitalRead(mode1_switch);
138152
uint8_t mode2_switchStatus = digitalRead(mode2_switch);
139153

154+
// if just switched to mode 1, change the color sequence
140155
if(mode1_switchStatus == false && prev_mode1Switch == true) {
141-
Serial.println("ARDUINO");
142156
colorCount = 0;
143157
strcpy(queryString, queryString1);
144158
for(uint8_t i=0; i<8; i++) {
@@ -153,15 +167,15 @@ void loop() {
153167
Serial.print(" ");
154168
Serial.print(lampShades[i].green);
155169
Serial.print(" ");
156-
Serial.println(lampShades[i].blue);
157-
170+
Serial.println(lampShades[i].blue);
158171
}
159172
analogWrite(pin_r, lampShades[0].red);
160173
analogWrite(pin_g, lampShades[0].green);
161174
analogWrite(pin_b, lampShades[0].blue);
162175
}
176+
177+
// if just switched to mode 2, change the color sequence
163178
else if(mode2_switchStatus == false && prev_mode2Switch == true) {
164-
Serial.println("CIAO");
165179
colorCount = 0;
166180
strcpy(queryString, queryString2);
167181
for(uint8_t i=0; i<8; i++) {
@@ -177,7 +191,6 @@ void loop() {
177191
Serial.print(lampShades[i].green);
178192
Serial.print(" ");
179193
Serial.println(lampShades[i].blue);
180-
181194
}
182195

183196
analogWrite(pin_r, lampShades[0].red);
@@ -187,12 +200,15 @@ void loop() {
187200
prev_mode1Switch = mode1_switchStatus;
188201
prev_mode2Switch = mode2_switchStatus;
189202

203+
// Use for debugging the the switch state
204+
/*
190205
Serial.print(prev_mode1Switch);
191206
Serial.print(" ");
192207
Serial.println(prev_mode2Switch);
193208
194209
Serial.println(queryString);
195210
Serial.println();
211+
*/
196212

197213
// Attempt server connection, with timeout...
198214
Serial.print(F("Connecting to server..."));
@@ -250,7 +266,6 @@ void loop() {
250266
Serial.println(F("failed"));
251267
}
252268

253-
254269
// Sometimes network access & printing occurrs so quickly, the steady-on
255270
// LED wouldn't even be apparent, instead resembling a discontinuity in
256271
// the otherwise smooth sleep throb. Keep it on at least 4 seconds.
@@ -315,13 +330,8 @@ boolean jsonParse(int depth, byte endChar) {
315330
}
316331
else if(!strcasecmp(name, "from_user")) {
317332
strncpy(fromUser, value, sizeof(fromUser)-1);
318-
/*
319-
colorCount++;
320-
if(colorCount == maxColorCount)
321-
colorCount = 0;
322-
*/
323-
Serial.println(colorCount);
324333

334+
// every time a new user post a tweet lest's fade up the LED
325335
uint8_t cc = (colorCount+1)%8;
326336

327337
fadeTo(lampShades[colorCount], lampShades[cc]);

0 commit comments

Comments
 (0)