This commit is contained in:
2014-09-25 17:40:03 +02:00
commit e5ca7e7403
12 changed files with 1915 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
int UD = 0;
int LR = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
UD = analogRead(A0);
LR = analogRead(A1);
if (UD == 0)
{
Serial.println("This is down!");
}
else
if (UD == 1023)
{
Serial.println("This is up!");
}
else
if (LR == 0)
{
Serial.println("This is Left!");
}
else
if (LR == 1023)
{
Serial.println("This is Right!");
}
delay(10);
}

View File

@@ -0,0 +1,72 @@
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int UD = 0;
int LR = 0;
const int buttonPin = 2;
char* myString [] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@Odinbn", "@hozar132"};
int length = 0;
int buttonState = 0;
int i = 0;
void setup(){
lcd.begin(16, 2);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop()
{
//Get length of myString
length = 5;
UD = analogRead(0);
LR = analogRead(1);
/*
if (UD > 512)
{
Serial.print("UP");
delay(800);
}
else
if (UD < 512)
{
Serial.print("Down");
delay(800);
}
else
if (LR < 512 && UD > 512)
{
Serial.print("Right");
delay(800);
}
else
if (LR < 512)
{
Serial.print("Left");
delay(800);
}*/
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
lcd.clear();
lcd.write(">");
lcd.write(myString[i]);
lcd.setCursor(1,1);
lcd.write(myString[i + 1]);
delay(800);
i++;
}
if (i >= length)
{
i = 0;
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

60
SimplePost/SimplePost.ino Normal file
View File

@@ -0,0 +1,60 @@
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>
// Ethernet Shield Settings
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51 };
const int buttonPin = 9;
int buttonState = 0;
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
//byte ip[] = { 192, 168, 2, 250 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
// Message to post
char msg[] = "@KevinMidboe Vannet er ferdig!";
void setup()
{
delay(1000);
Ethernet.begin(mac);
// or you can use DHCP for autoomatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
Serial.println("Ready!");
pinMode(buttonPin, INPUT);
buttonState = LOW;
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
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.");
}
delay(1000);
}
}

315
Tea-duino 2.0.pde Normal file
View File

@@ -0,0 +1,315 @@
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
char *menuTree[] = {"mainMenu", "Users", "Add user"};
char *mainMenu[] = {"Choose user", "Add user"};
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@Odinbn", "@Hozar132"};
char *itsDone[] = {"Vannet er ferdig!", "TEATIME!", "my Man, the water is done!"};
char *errorWhereIsBoiler [] = {"Sett vannkokeren", "pa knappen."};
char *startWaterMessage [] = {"Skru pa vannet!"};
byte CoffeeEmpty[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b10001, 0b01110};
byte CoffeeHank[8] = {
0b00000, 0b00000, 0b00000, 0b00000,
0b11000, 0b01000, 0b11000, 0b00000};
byte Coffee1[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b11111, 0b01110};
byte Coffee2[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b11111, 0b11111, 0b01110};
byte Coffee3[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke1[8] = {
0b00101, 0b01010, 0b00101, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke2[8] = {
0b01010, 0b00101, 0b01010, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
Twitter twitter("2307428619-TIM5H7Lh6L9HrrQLMynR5cinWpNbiUTt2827myM");
byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
const int buttonPin = 3;
int resetPin = 9;
int buttonState = 0;
int UD = 1;
int LR = 1;
boolean movedDown = false;
int upDownCount = 0;
int menuSelector = 0;
int mainMenuController = 0;
int animationSelector = 2;
char* username;
int lengthMainMenu = sizeof(mainMenu);
int lengthUserMenu = sizeof(twitterHandles);
void setup()
{
pinMode(resetPin, OUTPUT);
lcd.begin(16,2);
Ethernet.begin(mac);
lcd.createChar(1, CoffeeHank);
lcd.createChar(2, CoffeeEmpty);
lcd.createChar(3, Coffee1);
lcd.createChar(4, Coffee2);
lcd.createChar(5, Coffee3);
lcd.createChar(6, CoffeeSmoke1);
lcd.createChar(7, CoffeeSmoke2);
pinMode(buttonPin, INPUT);
upDownCount = writeMainMenu(movedDown, upDownCount);
}
void loop()
{
while (menuTree[menuSelector] == menuTree[0])
{
delay(200);
LR = analogRead(A0);
UD = analogRead(A1);
if (UD == 0)
{
movedDown = false;
upDownCount--;
if (upDownCount < 0)
{
upDownCount = 0;
}
upDownCount = writeMainMenu(movedDown, upDownCount);
}
if (UD == 1022)
{
movedDown = true;
upDownCount = writeMainMenu(movedDown, upDownCount);
upDownCount++;
}
if (LR == 0)
{
menuSelector = 1;
upDownCount = 0;
upDownCount = writeUserMenu(movedDown, upDownCount);
delay(400);
}
}
while (menuTree[menuSelector] == menuTree[1])
{
delay(200);
LR = analogRead(A0);
UD = analogRead(A1);
if (UD == 0)
{
movedDown = false;
upDownCount--;
if (upDownCount < 0)
{
upDownCount = 0;
}
upDownCount = writeUserMenu(movedDown, upDownCount);
}
if (UD == 1022)
{
movedDown = true;
upDownCount = writeUserMenu(movedDown, upDownCount);
upDownCount++;
}
if (LR == 0)
{
username = twitterHandles[upDownCount];
buttonState = digitalRead(buttonPin);
if (buttonState == LOW)
{
lcd.clear();
lcd.write(errorWhereIsBoiler[0]);
lcd.setCursor(0,1);
lcd.write(errorWhereIsBoiler[1]);
delay(2000);
upDownCount = writeUserMenu(movedDown, upDownCount);
}
else
{
checkWaterON(username);
}
}
if (LR == 1022)
{
menuSelector = 0;
upDownCount = 0;
upDownCount = writeMainMenu(movedDown, upDownCount);
}
}
}
int writeMainMenu(boolean movedDown, int upDownCount)
{
int i = upDownCount;
lcd.clear();
if (movedDown == false)
{
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
}
else
{
lcd.setCursor(1,0);
lcd.write(mainMenu[i]);
lcd.setCursor(0,1);
lcd.write(">");
lcd.write(mainMenu[i + 1]);
}
return i;
}
int writeUserMenu(boolean movedDown, int upDownCount)
{
int i = upDownCount;
lcd.clear();
if (movedDown == false)
{
lcd.write(">");
lcd.write(twitterHandles[i]);
lcd.setCursor(1,1);
lcd.write(twitterHandles[i + 1]);
}
else
{
lcd.setCursor(1,0);
lcd.write(twitterHandles[i]);
lcd.setCursor(0,1);
lcd.write(">");
lcd.write(twitterHandles[i + 1]);
}
return i;
}
void checkWaterON(char* username)
{
lcd.clear();
lcd.write(startWaterMessage[0]);
delay(1500);
buttonState = digitalRead(buttonPin);
if (buttonState == LOW)
{
waterOnAndTweet(username);
}
else
{
checkWaterON(username);
}
}
void waterOnAndTweet(char* username)
{
buttonState = digitalRead(buttonPin);
while (buttonState == LOW)
{
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(animationSelector);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(animationSelector);
lcd.setCursor(10, 1);
lcd.write(1);
animationSelector++;
delay(1500);
if (animationSelector == 6)
{
animationSelector = 2;
}
waterOnAndTweet(username);
}
if (twitter.post(username))
{
int status = twitter.wait(&lcd);
if (status == 200)
{
waitForPickup();
}
else
if(status == 403)
{
lcd.clear();
lcd.write("Duplicate tweet!");
lcd.setCursor(0,1);
lcd.write(status);
delay(65000);
twitter.post(username);
// int status = twitter.wait(&lcd);
// if(status == 200)
// {
// waitForPickup();
// }
// else
// {
// waterOnAndTweet(username);
// }
}
}
}
void waitForPickup()
{
buttonState = digitalRead(buttonPin);
while (buttonState == HIGH)
{
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(6);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(6);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1500);
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(7);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(7);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1500);
waitForPickup();
}
while (buttonState == LOW)
{
lcd.clear();
lcd.write("RESET!");
digitalWrite(resetPin, HIGH);
delay(3000);
}
}

284
Tea-duino.pde Normal file
View File

@@ -0,0 +1,284 @@
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
char *mainMenu[] = {"Choose user", "Add new user"};
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@OdinBN", "@Hozar132"};
char *alphabet[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3",
"4", "5", "6", "7", "8", "9"};
byte CoffeeEmpty[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b10001, 0b01110};
byte CoffeeHank[8] = {
0b00000, 0b00000, 0b00000, 0b00000,
0b11000, 0b01000, 0b11000, 0b00000};
byte Coffee1[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b11111, 0b01110};
byte Coffee2[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b11111, 0b11111, 0b01110};
byte Coffee3[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke1[8] = {
0b00101, 0b01010, 0b00101, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke2[8] = {
0b01010, 0b00101, 0b01010, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
//byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
char message[] = "Didn't have anyone to send to... :(";
const int buttonPin = 9;
int buttonState = 0;
int animatorSelector = 2;
int UD = 1;
int LR = 1;
int i = 1;
int j = 0;
int k = 0;
int lengthMainMenu = 2;
int lengthTwitterHandles = 5;
int lengthAlphabet = 36;
boolean boolMainMenu = true;
boolean boolTwitterHandles = false;
boolean waterBoiling = false;
int selected = 0;
void setup()
{
lcd.begin(16, 2);
pinMode(buttonPin, INPUT);
//Ethernet.begin(mac);
lcd.write("Ready!");
delay(1000);
lcd.clear();
lcd.createChar(1, CoffeeHank);
lcd.createChar(2, CoffeeEmpty);
lcd.createChar(3, Coffee1);
lcd.createChar(4, Coffee2);
lcd.createChar(5, Coffee3);
lcd.createChar(6, CoffeeSmoke1);
lcd.createChar(7, CoffeeSmoke2);
}
void loop()
{
while (boolMainMenu == true)
{
LR = analogRead(A0);
UD = analogRead(A1);
delay(300);
if (UD == 1022)
{
i = 0;
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
delay(800);
selected = 0;
}
if (UD == 0)
{
i = 0;
lcd.clear();
lcd.setCursor(1, 0);
lcd.write(mainMenu[i]);
lcd.setCursor(0, 1);
lcd.write(">");
lcd.write(mainMenu[i + 1]);
delay(800);
selected = 1;
}
LR = analogRead(A0);
UD = analogRead(A1);
if (LR == 1022)
{
if (selected == 0)
{
boolMainMenu = false;
boolTwitterHandles = true;
i = 0;
lcd.clear();
lcd.write(">");
lcd.write(twitterHandles[i]);
lcd.setCursor(1, 1);
lcd.write(twitterHandles[i + 1]);
}
else
if (selected == 1)
{
LR = analogRead(A0);
UD = analogRead(A1);
delay(300);
if (UD == 1022)
{
k++;
if (k == 37)
{
k = 0;
}
}
if (UD == 0)
{
k--;
if (k == -1)
{
k = 37;
}
}
lcd.clear();
lcd.write(alphabet[k]);
lcd.write(alphabet[k + 1]);
/*for(int k = 0; k < lengthTwitterHandles; k++)
{
}*/
if (LR == 0)
{
//Save the typed-inn name
//Add @ to the name
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
delay(800);
}
}
}
}
while(boolTwitterHandles == true)
{
LR = analogRead(A0);
UD = analogRead(A1);
delay(300);
if (UD == 0)
{
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
delay(800);
i++;
if (i == lengthMainMenu)
{
i = 0;
}
}
if (UD == 1022)
{
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i + 1]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i]);
delay(800);
i--;
if (i == 0)
{
//i = lengthMainMenu;
i = 1;
}
}
LR = analogRead(A0);
UD = analogRead(A1);
if (LR == 1022)
{
//ERROR
//Invalid conversion from 'char*' to 'char'
//message[] = twitterHandles[i];
waterBoiling = false;
boolTwitterHandles = false;
lcd.clear();
}
LR = analogRead(A0);
UD = analogRead(A1);
if (LR == 0)
{
boolTwitterHandles = false;
boolMainMenu = true;
i = 0;
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1, 1);
lcd.write(mainMenu[i + 1]);
}
}
//Maybe (while(waterBoiling == true && buttonState == LOW))
while(waterBoiling == true)
{
lcd.setCursor(9, 1);
lcd.write(animatorSelector);
lcd.setCursor(10, 1);
lcd.write(1);
animatorSelector++;
delay(3000);
lcd.clear();
if(animatorSelector > 5)
{
animatorSelector = 2;
}
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
twitter.post(message);
waterBoiling = false;
buttonState = digitalRead(buttonPin);
}
}
while(waterBoiling == false && buttonState == HIGH)
{
lcd.clear();
lcd.setCursor(9, 1);
lcd.write(6 + j);
lcd.setCursor(10, 1);
lcd.write(1);
j++;
delay(1200);
if (j == 2)
{
j = 0;
}
buttonState = digitalRead(buttonPin);
if(buttonState == LOW)
{
boolMainMenu = true;
lcd.clear();
}
}
}

View File

@@ -0,0 +1,200 @@
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
byte CoffeeEmpty[8] = {
0b00000,
0b00000,
0b00000,
0b11111,
0b10001,
0b10001,
0b10001,
0b01110
};
byte CoffeeHank[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b11000,
0b01000,
0b11000,
0b00000
};
byte Coffee1[8] = {
0b00000,
0b00000,
0b00000,
0b11111,
0b10001,
0b10001,
0b11111,
0b01110
};
byte Coffee2[8] = {
0b00000,
0b00000,
0b00000,
0b11111,
0b10001,
0b11111,
0b11111,
0b01110
};
byte Coffee3[8] = {
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b01110
};
byte CoffeeSmoke1[8] = {
0b00101,
0b01010,
0b00101,
0b11111,
0b11111,
0b11111,
0b11111,
0b01110
};
byte CoffeeSmoke2[8] = {
0b01010,
0b00101,
0b01010,
0b11111,
0b11111,
0b11111,
0b11111,
0b01110
};
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xA7, 0x51 };
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
char msg[] = "@KevinMidboe @SindreIvers";
int buttonPin = 9;
int animationSelector = 2;
int buttonState = 0;
boolean waterDone = false;
boolean tweeted = false;
void setup()
{
Ethernet.begin(mac);
//Serial.begin(9600);
lcd.createChar(1, CoffeeHank);
lcd.createChar(2, CoffeeEmpty);
lcd.createChar(3, Coffee1);
lcd.createChar(4, Coffee2);
lcd.createChar(5, Coffee3);
lcd.createChar(6, CoffeeSmoke1);
lcd.createChar(7, CoffeeSmoke2);
lcd.begin(16, 2);
pinMode(buttonPin, INPUT);
buttonState = LOW;
}
void loop()
{
while (waterDone == false)
{
lcd.setCursor(9, 1);
lcd.write(animationSelector);
lcd.setCursor(10, 1);
lcd.write(1);
animationSelector++;
delay(3000);
lcd.clear();
if (animationSelector > 5)
{
animationSelector = 2;
}
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
waterDone = true;
}
}
buttonState = digitalRead(buttonPin);
if (waterDone == true && buttonState == HIGH)
{
while(tweeted == false)
{
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.");
tweeted = true;
}
else
{
Serial.print("failed : code ");
Serial.println(status);
}
}
else
{
Serial.println("connection failed.");
}
}
}
while(buttonState == HIGH && tweeted == true)
{
delay(1000);
lcd.clear();
lcd.setCursor(9, 1);
lcd.write(6);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1200);
lcd.clear();
lcd.setCursor(9, 1);
lcd.write(7);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1200);
buttonState = digitalRead(buttonPin);
}
if (buttonState == LOW && tweeted == true)
{
lcd.clear();
lcd.write(">Choose User");
lcd.setCursor(1, 1);
lcd.write("Add new User");
delay(4000);
}
}

284
Tea_duino/Tea_duino.ino Normal file
View File

@@ -0,0 +1,284 @@
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
char *mainMenu[] = {"Choose user", "Add new user"};
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@OdinBN", "@Hozar132"};
char *alphabet[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3",
"4", "5", "6", "7", "8", "9"};
byte CoffeeEmpty[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b10001, 0b01110};
byte CoffeeHank[8] = {
0b00000, 0b00000, 0b00000, 0b00000,
0b11000, 0b01000, 0b11000, 0b00000};
byte Coffee1[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b11111, 0b01110};
byte Coffee2[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b11111, 0b11111, 0b01110};
byte Coffee3[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke1[8] = {
0b00101, 0b01010, 0b00101, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke2[8] = {
0b01010, 0b00101, 0b01010, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
//byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
char message[] = "Didn't have anyone to send to... :(";
const int buttonPin = 9;
int buttonState = 0;
int animatorSelector = 2;
int UD = 1;
int LR = 1;
int i = 1;
int j = 0;
int k = 0;
int lengthMainMenu = 2;
int lengthTwitterHandles = 5;
int lengthAlphabet = 36;
boolean boolMainMenu = true;
boolean boolTwitterHandles = false;
boolean waterBoiling = false;
int selected = 0;
void setup()
{
lcd.begin(16, 2);
pinMode(buttonPin, INPUT);
//Ethernet.begin(mac);
lcd.write("Ready!");
delay(1000);
lcd.clear();
lcd.createChar(1, CoffeeHank);
lcd.createChar(2, CoffeeEmpty);
lcd.createChar(3, Coffee1);
lcd.createChar(4, Coffee2);
lcd.createChar(5, Coffee3);
lcd.createChar(6, CoffeeSmoke1);
lcd.createChar(7, CoffeeSmoke2);
}
void loop()
{
while (boolMainMenu == true)
{
LR = analogRead(A0);
UD = analogRead(A1);
delay(300);
if (UD == 1022)
{
i = 0;
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
delay(800);
selected = 0;
}
if (UD == 0)
{
i = 0;
lcd.clear();
lcd.setCursor(1, 0);
lcd.write(mainMenu[i]);
lcd.setCursor(0, 1);
lcd.write(">");
lcd.write(mainMenu[i + 1]);
delay(800);
selected = 1;
}
LR = analogRead(A0);
UD = analogRead(A1);
if (LR == 1022)
{
if (selected == 0)
{
boolMainMenu = false;
boolTwitterHandles = true;
i = 0;
lcd.clear();
lcd.write(">");
lcd.write(twitterHandles[i]);
lcd.setCursor(1, 1);
lcd.write(twitterHandles[i + 1]);
}
else
if (selected == 1)
{
LR = analogRead(A0);
UD = analogRead(A1);
delay(300);
if (UD == 1022)
{
k++;
if (k == 37)
{
k = 0;
}
}
if (UD == 0)
{
k--;
if (k == -1)
{
k = 37;
}
}
lcd.clear();
lcd.write(alphabet[k]);
lcd.write(alphabet[k + 1]);
/*for(int k = 0; k < lengthTwitterHandles; k++)
{
}*/
if (LR == 0)
{
//Save the typed-inn name
//Add @ to the name
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
delay(800);
}
}
}
}
while(boolTwitterHandles == true)
{
LR = analogRead(A0);
UD = analogRead(A1);
delay(300);
if (UD == 0)
{
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
delay(800);
i++;
if (i == lengthMainMenu)
{
i = 0;
}
}
if (UD == 1022)
{
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i + 1]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i]);
delay(800);
i--;
if (i == 0)
{
//i = lengthMainMenu;
i = 1;
}
}
LR = analogRead(A0);
UD = analogRead(A1);
if (LR == 1022)
{
//ERROR
//Invalid conversion from 'char*' to 'char'
//message[] = twitterHandles[i];
waterBoiling = false;
boolTwitterHandles = false;
lcd.clear();
}
LR = analogRead(A0);
UD = analogRead(A1);
if (LR == 0)
{
boolTwitterHandles = false;
boolMainMenu = true;
i = 0;
lcd.clear();
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1, 1);
lcd.write(mainMenu[i + 1]);
}
}
//Maybe (while(waterBoiling == true && buttonState == LOW))
while(waterBoiling == true)
{
lcd.setCursor(9, 1);
lcd.write(animatorSelector);
lcd.setCursor(10, 1);
lcd.write(1);
animatorSelector++;
delay(3000);
lcd.clear();
if(animatorSelector > 5)
{
animatorSelector = 2;
}
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
twitter.post(message);
waterBoiling = false;
buttonState = digitalRead(buttonPin);
}
}
while(waterBoiling == false && buttonState == HIGH)
{
lcd.clear();
lcd.setCursor(9, 1);
lcd.write(6 + j);
lcd.setCursor(10, 1);
lcd.write(1);
j++;
delay(1200);
if (j == 2)
{
j = 0;
}
buttonState = digitalRead(buttonPin);
if(buttonState == LOW)
{
boolMainMenu = true;
lcd.clear();
}
}
}

View File

@@ -0,0 +1,315 @@
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
char *menuTree[] = {"mainMenu", "Users", "Add user"};
char *mainMenu[] = {"Choose user", "Add user"};
char *twitterHandles[] = {"@EchoEsq", "@SindreIvers", "@KevinMidboe", "@Odinbn", "@Hozar132"};
char *itsDone[] = {"Vannet er ferdig!", "TEATIME!", "my Man, the water is done!"};
char *errorWhereIsBoiler [] = {"Sett vannkokeren", "pa knappen."};
char *startWaterMessage [] = {"Skru pa vannet!"};
byte CoffeeEmpty[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b10001, 0b01110};
byte CoffeeHank[8] = {
0b00000, 0b00000, 0b00000, 0b00000,
0b11000, 0b01000, 0b11000, 0b00000};
byte Coffee1[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b11111, 0b01110};
byte Coffee2[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b11111, 0b11111, 0b01110};
byte Coffee3[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke1[8] = {
0b00101, 0b01010, 0b00101, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke2[8] = {
0b01010, 0b00101, 0b01010, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
Twitter twitter("2307428619-TIM5H7Lh6L9HrrQLMynR5cinWpNbiUTt2827myM");
byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
const int buttonPin = 3;
int resetPin = 3;
int buttonState;
int UD = 1;
int LR = 1;
boolean movedDown = false;
int upDownCount = 0;
int menuSelector = 0;
int mainMenuController = 0;
int animationSelector = 2;
char* username;
int lengthMainMenu = sizeof(mainMenu);
int lengthUserMenu = sizeof(twitterHandles);
void setup()
{
pinMode(resetPin, OUTPUT);
lcd.begin(16,2);
Ethernet.begin(mac);
lcd.createChar(1, CoffeeHank);
lcd.createChar(2, CoffeeEmpty);
lcd.createChar(3, Coffee1);
lcd.createChar(4, Coffee2);
lcd.createChar(5, Coffee3);
lcd.createChar(6, CoffeeSmoke1);
lcd.createChar(7, CoffeeSmoke2);
pinMode(buttonPin, INPUT);
upDownCount = writeMainMenu(movedDown, upDownCount);
}
void loop()
{
while (menuTree[menuSelector] == menuTree[0])
{
delay(200);
LR = analogRead(A0);
UD = analogRead(A1);
if (UD == 0)
{
movedDown = false;
upDownCount--;
if (upDownCount < 0)
{
upDownCount = 0;
}
upDownCount = writeMainMenu(movedDown, upDownCount);
}
if (UD == 1022)
{
movedDown = true;
upDownCount = writeMainMenu(movedDown, upDownCount);
upDownCount++;
}
if (LR == 0)
{
menuSelector = 1;
upDownCount = 0;
upDownCount = writeUserMenu(movedDown, upDownCount);
delay(400);
}
}
while (menuTree[menuSelector] == menuTree[1])
{
delay(200);
LR = analogRead(A0);
UD = analogRead(A1);
if (UD == 0)
{
movedDown = false;
upDownCount--;
if (upDownCount < 0)
{
upDownCount = 0;
}
upDownCount = writeUserMenu(movedDown, upDownCount);
}
if (UD == 1022)
{
movedDown = true;
upDownCount = writeUserMenu(movedDown, upDownCount);
upDownCount++;
}
if (LR == 0)
{
username = twitterHandles[upDownCount];
buttonState = analogRead(buttonPin);
if (buttonState != 0)
{
lcd.clear();
lcd.write(errorWhereIsBoiler[0]);
lcd.setCursor(0,1);
lcd.write(errorWhereIsBoiler[1]);
delay(2000);
upDownCount = writeUserMenu(movedDown, upDownCount);
}
else
{
checkWaterON(username);
}
}
if (LR == 1022)
{
menuSelector = 0;
upDownCount = 0;
upDownCount = writeMainMenu(movedDown, upDownCount);
}
}
}
int writeMainMenu(boolean movedDown, int upDownCount)
{
int i = upDownCount;
lcd.clear();
if (movedDown == false)
{
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
}
else
{
lcd.setCursor(1,0);
lcd.write(mainMenu[i]);
lcd.setCursor(0,1);
lcd.write(">");
lcd.write(mainMenu[i + 1]);
}
return i;
}
int writeUserMenu(boolean movedDown, int upDownCount)
{
int i = upDownCount;
lcd.clear();
if (movedDown == false)
{
lcd.write(">");
lcd.write(twitterHandles[i]);
lcd.setCursor(1,1);
lcd.write(twitterHandles[i + 1]);
}
else
{
lcd.setCursor(1,0);
lcd.write(twitterHandles[i]);
lcd.setCursor(0,1);
lcd.write(">");
lcd.write(twitterHandles[i + 1]);
}
return i;
}
void checkWaterON(char* username)
{
lcd.clear();
lcd.write(startWaterMessage[0]);
delay(1500);
buttonState = analogRead(buttonPin);
if (buttonState != 0)
{
waterOnAndTweet(username);
}
else
{
checkWaterON(username);
}
}
void waterOnAndTweet(char* username)
{
buttonState = analogRead(buttonPin);
while (buttonState != 0)
{
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(animationSelector);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(animationSelector);
lcd.setCursor(10, 1);
lcd.write(1);
animationSelector++;
delay(1500);
if (animationSelector == 6)
{
animationSelector = 2;
}
waterOnAndTweet(username);
}
if (twitter.post(username))
{
int status = twitter.wait(&lcd);
if (status == 200)
{
waitForPickup();
}
else
if(status == 403)
{
lcd.clear();
lcd.write("Duplicate tweet!");
lcd.setCursor(0,1);
lcd.write(status);
delay(65000);
twitter.post(username);
// int status = twitter.wait(&lcd);
// if(status == 200)
// {
// waitForPickup();
// }
// else
// {
// waterOnAndTweet(username);
// }
}
}
}
void waitForPickup()
{
buttonState = analogRead(buttonPin);
while (buttonState == 0)
{
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(6);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(6);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1500);
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(7);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(7);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1500);
waitForPickup();
}
while (buttonState != 0)
{
lcd.clear();
lcd.write("RESET!");
digitalWrite(resetPin, HIGH);
delay(3000);
}
}

View File

@@ -0,0 +1,354 @@
#include <LiquidCrystal.h>
#include <JoystickController.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
LiquidCrystal lcd(0, 1, 2, 6, 7, 8);
char *menuTree[] = {"mainMenu", "Users", "Add user"};
char *mainMenu[] = {"Choose user", "Add user"};
char *twitterHandles[] = {"@KevinMidboe ", "@EchoEsq ", "@SindreIvers ", "@Hozar132 ", "@Odinbn "};
char *donePhrases[] = {"Vannet er ferdig! ", "TEATIME ", "my man, the water is done! ", "Kom å hent meg! "};
char *errorWhereIsBoiler [] = {"Sett vannkokeren", "pa knappen."};
char *startWaterMessage [] = {"Skru pa vannet!"};
byte CoffeeEmpty[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b10001, 0b01110};
byte CoffeeHank[8] = {
0b00000, 0b00000, 0b00000, 0b00000,
0b11000, 0b01000, 0b11000, 0b00000};
byte Coffee1[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b10001, 0b11111, 0b01110};
byte Coffee2[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b10001, 0b11111, 0b11111, 0b01110};
byte Coffee3[8] = {
0b00000, 0b00000, 0b00000, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke1[8] = {
0b00101, 0b01010, 0b00101, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
byte CoffeeSmoke2[8] = {
0b01010, 0b00101, 0b01010, 0b11111,
0b11111, 0b11111, 0b11111, 0b01110};
Twitter twitter("2307428619-TIM5H7Lh6L9HrrQLMynR5cinWpNbiUTt2827myM");
byte mac[] = {0x90, 0xA2, 0xDa, 0x0d, 0xA7, 0x51};
const int buttonPin = 3;
const int resetPin = 3;
int buttonState;
int UD = 1;
int LR = 1;
boolean movedDown = false;
int upDownCount = 0;
int menuSelector = 0;
int mainMenuController = 0;
int animationSelector = 2;
char* username;
char buf[100];
int lengthMainMenu = sizeof(mainMenu);
int lengthUserMenu = sizeof(twitterHandles);
JoystickController controller;
void setup()
{
lcd.begin(16,2);
Ethernet.begin(mac);
lcd.createChar(1, CoffeeHank);
lcd.createChar(2, CoffeeEmpty);
lcd.createChar(3, Coffee1);
lcd.createChar(4, Coffee2);
lcd.createChar(5, Coffee3);
lcd.createChar(6, CoffeeSmoke1);
lcd.createChar(7, CoffeeSmoke2);
pinMode(buttonPin, INPUT);
upDownCount = writeMainMenu(movedDown, upDownCount);
}
void loop()
{
while (menuTree[menuSelector] == menuTree[0])
{
delay(200);
controller.update();
int direct = controller.getDirection();
switch (direct)
{
case JoystickController::DIRECTION_RIGHT:
{
movedDown = false;
upDownCount--;
if (upDownCount < 0)
{
upDownCount = 0;
}
upDownCount = writeMainMenu(movedDown, upDownCount);
break;
}
case JoystickController::DIRECTION_LEFT:
{
movedDown = true;
upDownCount = writeMainMenu(movedDown, upDownCount);
upDownCount++;
break;
}
case JoystickController::DIRECTION_DOWN:
{
menuSelector = 1;
upDownCount = 0;
upDownCount = writeUserMenu(movedDown, upDownCount);
delay(400);
break;
}
}
}
while (menuTree[menuSelector] == menuTree[1])
{
delay(200);
controller.update();
int direct = controller.getDirection();
switch (direct)
{
case JoystickController::DIRECTION_RIGHT:
{
movedDown = false;
upDownCount--;
if (upDownCount < 0)
{
upDownCount = 0;
}
upDownCount = writeUserMenu(movedDown, upDownCount);
break;
}
case JoystickController::DIRECTION_LEFT:
{
movedDown = true;
upDownCount = writeUserMenu(movedDown, upDownCount);
upDownCount++;
break;
}
case JoystickController::DIRECTION_DOWN:
{
username = twitterHandles[upDownCount];
buttonState = analogRead(buttonPin);
if (buttonState != 0)
{
lcd.clear();
lcd.write(errorWhereIsBoiler[0]);
lcd.setCursor(0,1);
lcd.write(errorWhereIsBoiler[1]);
delay(2000);
upDownCount = writeUserMenu(movedDown, upDownCount);
}
else
{
checkWaterON(username);
}
}
case JoystickController::DIRECTION_UP :
{
menuSelector = 0;
upDownCount = 0;
upDownCount = writeMainMenu(movedDown, upDownCount);
break;
}
}
}
}
int writeMainMenu(boolean movedDown, int upDownCount)
{
int i = upDownCount;
lcd.clear();
if (movedDown == false)
{
lcd.write(">");
lcd.write(mainMenu[i]);
lcd.setCursor(1,1);
lcd.write(mainMenu[i + 1]);
}
else
{
lcd.setCursor(1,0);
lcd.write(mainMenu[i]);
lcd.setCursor(0,1);
lcd.write(">");
lcd.write(mainMenu[i + 1]);
}
return i;
}
int writeUserMenu(boolean movedDown, int upDownCount)
{
int i = upDownCount;
lcd.clear();
if (movedDown == false)
{
lcd.write(">");
lcd.write(twitterHandles[i]);
lcd.setCursor(1,1);
lcd.write(twitterHandles[i + 1]);
}
else
{
lcd.setCursor(1,0);
lcd.write(twitterHandles[i]);
lcd.setCursor(0,1);
lcd.write(">");
lcd.write(twitterHandles[i + 1]);
}
return i;
}
void checkWaterON(char* username)
{
lcd.clear();
lcd.write(startWaterMessage[0]);
delay(1500);
buttonState = analogRead(buttonPin);
if (buttonState != 0)
{
waterOn(username);
}
else
{
checkWaterON(username);
}
}
void waterOn(char* username)
{
buttonState = analogRead(buttonPin);
while (buttonState != 0)
{
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(animationSelector);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(animationSelector);
lcd.setCursor(10, 1);
lcd.write(1);
animationSelector++;
delay(1500);
if (animationSelector == 6)
{
animationSelector = 2;
}
waterOn(username);
}
tweet(username);
}
void tweet(char* username)
{
String str(username);
randomSeed(analogRead(4));
long i = random(4);
int j(i);
String str2(donePhrases[j]);
str += str2;
i = random(20);
int k(i);
str += k;
char charBuf[140];
str.toCharArray(charBuf, 140);
twitter.post(charBuf);
/*if ()
{
int status = twitter.wait(&lcd);
if(status == 403)
{
if (j == 0)
{
j++;
}
else
if (j == 4)
{
j--;
}
else
{
j++;
}
String str3(username);
String str4(donePhrases[j]);
str3 += str4;
char charBuf1[140];
str3.toCharArray(charBuf1, 140);
twitter.post(charBuf1);
}
}*/
waitForPickup();
}
void waitForPickup()
{
buttonState = analogRead(buttonPin);
while (buttonState == 0)
{
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(6);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(6);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1500);
lcd.clear();
lcd.setCursor(6, 1);
lcd.write(7);
lcd.setCursor(7, 1);
lcd.write(1);
lcd.setCursor(9, 1);
lcd.write(7);
lcd.setCursor(10, 1);
lcd.write(1);
delay(1500);
waitForPickup();
}
if (buttonState != 0)
{
reset();
}
}
void reset()
{
lcd.clear();
lcd.write("RESET!");
delay(3000);
pinMode(resetPin, OUTPUT);
digitalWrite(resetPin, HIGH);
}