Skip to content

Instantly share code, notes, and snippets.

@m3nd3s
Created November 28, 2011 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m3nd3s/1402122 to your computer and use it in GitHub Desktop.
Save m3nd3s/1402122 to your computer and use it in GitHub Desktop.
Código da Andreia
################ CODIGO TWITTER
/*
ThingTweet App to Update a Twitter Status
The ThingTweet sketch is designed for the Arduino + Ethernet Shield.
This sketch updates a Twitter status via the ThingTweet App
(http://community.thingspeak.com/documentation/apps/thingtweet/) using HTTP POST.
ThingTweet is a Twitter proxy web application that handles the OAuth.
Getting Started with ThingSpeak and ThingTweet:
* Sign Up for a New User Account for ThingSpeak - https://www.thingspeak.com/users/new
* Link your Twitter account to the ThingTweet App - Apps / ThingTweet
* Enter the ThingTweet API Key in this sketch under "ThingSpeak Settings"
Created: March 7, 2011 by Hans Scharler (http://www.iamshadowlord.com)
*/
#include <SPI.h>
#include <Ethernet.h>
// Local Network Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
// ThingSpeak Settings
byte server[] = { 184, 106, 153, 149 }; // IP Address for the ThingSpeak API
String thingtweetAPIKey = "625IQ2W6ZGJHAEHX"; // Write API Key for a ThingSpeak Channel
Client client(server, 80);
// Variable Setup
boolean lastConnected = false;
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
delay(1000);
// Update Twitter via ThingTweet
if(!client.connected())
{
updateTwitterStatus("Alguém na portaaa!");
}
}
void loop()
{
// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
Serial.println();
Serial.println("...disconnected.");
Serial.println();
client.stop();
}
lastConnected = client.connected();
}
void updateTwitterStatus(String tsData)
{
if (client.connect() && tsData.length() > 0)
{
// Create HTTP POST Data
tsData = "api_key="+thingtweetAPIKey+"&status="+tsData;
Serial.println("Connected to ThingTweet...");
Serial.println();
client.print("POST /apps/thingtweet/1/statuses/update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
}
else
{
Serial.println("Connection Failed.");
Serial.println();
}
}
################ CODIGO PUSHBUTTON (ACENDE O LED)
int ledPin = 13; // porta 13 em output para o LED
int inPin = 7; // porta 7 em input (para o push button)
int val = 0; // variável para ler o status do pino
void setup() {
pinMode(ledPin, OUTPUT); // declare LED como output
pinMode(inPin, INPUT); // declare pushbutton como input
}
void loop(){
val = digitalRead(inPin); // ler a entrada de valor
if (val == LOW) {// verificar se a entrada é baixa
digitalWrite(ledPin, LOW); // LED OFF
} else {
digitalWrite(ledPin, HIGH); // LED ON
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment