-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitterPost.ino
More file actions
71 lines (63 loc) · 1.81 KB
/
Copy pathtwitterPost.ino
File metadata and controls
71 lines (63 loc) · 1.81 KB
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
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h>
#include "twtr.h"
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("YourToken");
char ssid[] = "YourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
char msgLight[] = "I'm Arduino! Someone is shining a light on me...";
char msgDark[] = "I'm Arduino! It's so dark in here. Anyone have a flashlight?";
bool lights_on = false;
void setup()
{
Serial.println("Connecting to network...");
delay(1000);
WiFi.begin(ssid, pass);
// or you can use DHCP for automatic IP address configuration.
// WiFi.begin(mac);
delay(10000);
Serial.println("...");
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
//Serial.println(voltage);
if(voltage > 2) {
// Lighted
if(!lights_on) {
Serial.println("Shining...");
lights_on = true;
sendTweet(msgLight);
}
} else {
// Dark
if(lights_on) {
Serial.println("Dark...");
lights_on = false;
sendTweet(msgDark);
}
}
}
void sendTweet(char *msg)
{
Serial.println("connecting ...");
if (twitter.post(msg)) {
// Specify &Serial to output received response to Serial.
// If no output is required, you can just omit the argument, e.g.
// int status = twitter.wait();
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}