Afternoon all!
I apologise if the name is slightly deceptive, this isn't a robot that will physically make the tea. But it is a robot that will get tea made (if that makes any sense). The first project I made with my GLCD (192x64) was one that I had been promising my mother I would do for ages, a robot that will get tea made for her. As I have few motors and materials for a robotic arm (Mum is also afraid of me using any voltage above about 50, don't tell her about the stripped out plasma ball) I decided that the best way to get teas made would be to make a device to order the tea to be made! So here it is: The Tea-o-matic
And here is the code I hope it is well enough commented, if you have a smaller GLCD then you may need to alter the messages and the title placement (0,3) should do.
#include <Arial14.h> //Title font
#include <ks0108.h> //GLCD Library
#include <step11.h> //Hello Bitmap
#include <SystemFont5x7.h> //Fixed width font
int turn = random(1,5); //Whos turn it is (random)
int pinBtn = 2; //The pin the button is on
int wasOnLastLoop; //Weather the button was
// pressed on the last
// loop
int ledPin = 13; //LED for visualization of
// sound (use 13 for
// built-in led)
int backPin = 12; //Pin the the backlight is
// connected to (for
// notification that some
// -one has been selected
int speakerPin = 3; //speaker connected to one
// of the PWM ports
//frequencies for the tones we can to use
//used http://home.mit.bme.hu/~bako/tonecalc/tonecalc.htm to
// get more of these
#define c 261 //C
#define d 294 //D
#define e 329 //E
#define f 349 //F
#define g 391 //G
#define gS 415 //G Sharp
#define a 440 //A
#define aS 455 //A Sharp
#define b 466 //B
#define cH 523 //C High
#define cSH 554 //C High Sharp
#define dH 587 //D High
#define dSH 622 //D High Sharp
#define eH 659 //E High
#define fH 698 //F High
#define fSH 740 //F High Sharp
#define gH 784 //G High
#define gSH 830 //G High Sharp
#define aH 880 //A High
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)
{
digitalWrite(ledPin, HIGH);
//use led to visualize the notes being played
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x<loopTime;x++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayAmount);
}
digitalWrite(ledPin, LOW);
//set led back to low
delay(20);
//a little delay to make all notes sound separate
}
void setup(){
//
//Pin Setup
//
pinMode(pinBtn, INPUT); //Sets the Button to an input
pinMode(ledPin, OUTPUT); //Sets the ledPin to be an output
pinMode(speakerPin, OUTPUT); //Sets the speakerPin to be an output
pinMode(backPin, OUTPUT); //Sets the Backlight Pin to be an output
digitalWrite(backPin, HIGH); //Switches the LCD Backlight on.
//
//GLCD Setup
//
GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
GLCD.SelectFont(System5x7);
//
//GLCD Test
//
GLCD.DrawBitmap(step11, 32,0,WHITE);
delay(1000);
for(int i = 0; i < 192; i++){
GLCD.DrawVertLine(i, 0, 64, BLACK);
delay(2);
}
for(int i = 0; i < 192; i++){
GLCD.DrawVertLine(i, 0, 64, WHITE);
delay(2);
}
//march();
whosTurn();
Serial.begin(9600);
}
void loop(){
//Go through this all the while the user holds the button down
while(digitalRead(pinBtn) == 1){
GLCD.ClearScreen(); //Remove the last frame
wasOnLastLoop=1; //Make sure the program knows that this was ran
// on the last loop execution
whosTurn(); //Display who's turn it is to make tea and
// redraw the title (GLCD.ClearScreen()
// erased it.)
turn = random(1, 5); //Chose a person (int 1-4 incl.) to make tea
// next
delay(100); //Allow the user time to see what is in the
// frame
}
if(wasOnLastLoop==1)
{
//**********************************************************
//Play a noise so everyone knows someone has to make the tea
tone(speakerPin, aH, 300); //Play note A High
delay(300); //Wait for note to finish
tone(speakerPin, a, 300); //Play note A
delay(300); //Waait for note to finish
tone(speakerPin, aH, 300); //Play note A High
//**********************************************************
//Flash backlight
flashBackLight();
//**********************************************************
//===================== Prevent cheating ===================
for(int i = 0; i < 6000; i++){ //Loop 6000 times
if(digitalRead(pinBtn) == 1){ //Is someone tring
// to go again?
tone(speakerPin, c, 500); //Make a noise
//Turn the backlight back on
digitalWrite(backPin, HIGH);
//
//Write out why it didn't select another person
//
GLCD.CursorTo(0,5);
GLCD.Puts("You must wait ten minutes before");
GLCD.CursorTo(0,6);
GLCD.Puts(" I can provide with the next");
GLCD.CursorTo(0,7);
GLCD.Puts(" persons name!");
//
//Flash backlight
//
flashBackLight();
}
//Make the loop take some time, 6000x100 = 10 mins
delay(100);
}
//Ok, we have done this now, don't need to prevent cheating next
// time around, wait till the user releases the button next
// before running this code again
wasOnLastLoop = 0;
}
Serial.println(digitalRead(pinBtn)); //For debugging
}
void flashBackLight(){
//**********************************************************
//Make the screen flash (assuming the backlight is on backPin
digitalWrite(backPin, HIGH); //On
delay(200); //Wait
digitalWrite(backPin,LOW); //Off
delay(200); //Wait
digitalWrite(backPin, HIGH); //On
delay(200); //Wait
digitalWrite(backPin,LOW); //Off
delay(200); //Wait
digitalWrite(backPin, HIGH); //On
delay(200); //Wait
digitalWrite(backPin,LOW); //Off
delay(200); //Wait
digitalWrite(backPin, HIGH); //On
//**********************************************************
}
void whosTurn(){
GLCD.SelectFont(Arial_14); //Title font
GLCD.CursorTo(5,0); //Centre screen
GLCD.Puts("Tea-o-matic!"); //Title itself
GLCD.DrawHoriLine(0, 12, 192, BLACK); //Underline the title
GLCD.SelectFont(System5x7); //Main font
GLCD.CursorTo(0,2); //Body location
switch(turn){
case 1: //Turn = 1
//Simon's turn
GLCD.Puts("Simon's Turn");//Write to screen
break;
case 2: //Turn = 2
//Laura's turn
GLCD.Puts("Laura has to make it");//Write to screen
break;
case 3: //Turn = 3
//Mum's turn
GLCD.Puts("Mum must put the kettle on");//Write to screen
break;
case 4: //Turn = 4
//Dad's turn
GLCD.Puts("Now Dad has to make the tea!!");//Write to screen
break;
}
}