// Including wifi and internet connectivity libraries
#include <Dhcp.h>
#include <Dns.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
//defines the pin connections
int GroundPin= A0;
int LEDPin= 4;
int count = 0;
int score = 0;
//defines normal and threshold voltage levels
int threshold= 500;
//sets GroundPin and LEDPin as output pins, with GroundPin being set to LOW
void setup()
{
Serial.begin(9600);
pinMode(GroundPin, OUTPUT);
digitalWrite(GroundPin, LOW);
pinMode(LEDPin, OUTPUT);
}
//if the reading is higher than the threshold value, then the LED is turned on
void loop()
{
int reading= analogRead(GroundPin);
Serial.println(reading);
if (reading > threshold)
{
count=count ++;
digitalWrite(LEDPin, HIGH);
delay(1000);
digitalWrite(LEDPin, LOW);
tweetMessage(count);
}}
void tweetMessage(int count) {
Twitter twitter("Your Twitter Token Here");
if (count >= 5)
{
score = score ++;
String stringMsg = "I'm Full! - Temperature Reading: ";
stringMsg += analogRead(A1);
stringMsg += " Score: " + score;
//Convert String to Char for posting on twitter
char msg[140];
stringMsg.toCharArray(msg, 140);
twitter.post(msg);
count = 0;
}
else
{
String stringMsg = "Temperature Reading: ";
stringMsg += analogRead(A1);
stringMsg += "Score: " + score;
//Convert String to Char for posting on twitter
char msg[140];
stringMsg.toCharArray(msg, 140);
twitter.post(msg);
}
}
Ali Mohamed Hussein
2 projects • 2 followers
Ever since I was a child, I've always wanted to make the games I played on my Playstation and on my PC.
Comments