#define CUSTOM_SETTINGS
#define INCLUDE_GLCD_SHIELD
#include <OneSheeld.h>
int ledPin1 = 13;
int ledPin2 = 12;
int relayPin = 11;
bool fanOn = false;
bool firstTimePressed = false;
GLCDRectangle border1(0,0,255,127);
GLCDRectangle border2(2,2,251,123);
/* The three Buttons.*/
GLCDButton lightButton1(20,49,50,30,"Light1");
GLCDButton lightButton2(105,49,50,30,"Light2");
GLCDButton fan(175,49,70,30,"FAN:OFF");
void setup()
{
/* Start communication. */
OneSheeld.begin();
/* Clear the GLCD. */
GLCD.clear();
/* Draw the three buttons. */
drawAllShapes();
/* Change the styles of the buttons to 3D. */
setButtonStyles();
/* Set the button handlers. */
setButtonTasks();
/* Set the two LEDs and the relay pins modes to output. */
pinMode(ledPin1,OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(relayPin,OUTPUT);
}
void loop()
{
/* Leave the loop empty. */
}
void drawAllShapes()
{
/* Draw the two borders and the three buttons. */
GLCD.draw(border1);
GLCD.draw(border2);
GLCD.draw(lightButton1);
GLCD.draw(lightButton2);
GLCD.draw(fan);
}
void setButtonTasks()
{
lightButton1.setOnChange(&button1Task);
lightButton2.setOnChange(&button2Task);
fan.setOnChange(&coffeeMakerTask);
}
void setButtonStyles()
{
lightButton1.setStyle(STYLE_3D);
lightButton2.setStyle(STYLE_3D);
fan.setStyle(STYLE_3D);
}
void button1Task(bool button1State)
{
if(button1State)
{
digitalWrite(ledPin1,HIGH);
}
else
{
digitalWrite(ledPin1,LOW);
}
}
void button2Task(bool button2State)
{
if(button2State)
{
digitalWrite(ledPin2,HIGH);
}
else
{
digitalWrite(ledPin2,LOW);
}
}
void coffeeMakerTask(bool fanState)
{
if(fanState)
{
if(firstTimePressed)
{
digitalWrite(relayPin,LOW);
fan.setText("FAN:ON");
fanOn = true;
firstTimePressed = false;
}
else
{
digitalWrite(relayPin,HIGH);
fan.setText("FAN:OFF");
fanOn = false;
}
}
else if(!fanOn)
{
firstTimePressed = true;
}
}
Comments
Please log in or sign up to comment.