아두이노 - 트위터에 글씨 올리기
1.버튼을 누르면,아두이노에서 트위터에 글씨를 올리자
그림 (생략) -코드참조
스케치
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
// Ethernet Settings
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x51, 0x24}; // No need to change the default Mac address
// OAuth Token
// Get your Token here: http://cd64.de/arduino-twitter-token
Twitter twitter("860681569-h8OtbfBYlCvZ2Y1EQ3JFXaGmQ7M5B4NICSnAYQvG");
// Counter
int i=0; // start with zero
char buf[100];
// Pin
int buttonPin = 7; // Pin for the push button
void setup() {
pinMode(buttonPin, INPUT);
Ethernet.begin(mac);
Serial.begin(9600);
}
void loop() {
if (digitalRead(buttonPin) == HIGH) {
// convert everything to string(char)
// sprintf(buf, "This is tweet number %d via an #Arduino Ethernet Board!", i);
sprintf(buf, "이것은 아두이노에서 %d 번째 쓴글입니다.", i);
tweet(buf);
i++;
// zero delay
delay(100000);
}
}
void tweet(char msg[]) {
Serial.println("connecting ...");
if (twitter.post(msg)) {
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}