Things used in this project

Schematics

GLCD%20Shield_bb.png
Glcd%20shield bb
GLCD Shield.fzz
GLCD Shield.fzz

Code

Untitled fileArduino
#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;
  }
}
Codebender

Credits

4fadba1074111a2a601f61a46a8e403c
Mahmoud Osman

Student

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

MannyBot365
Intermediate
  • 2,306
  • 26

Home automation system.

MannyBot365

3 members

Access Control with Arduino
Intermediate
  • 11,086
  • 13

Work in progress

Project that integrates Arduino, RTC display with I2C, RFID reader and SD card module.

Chameleon Monitoring System
Intermediate
  • 308
  • 5

Full instructions

Monitor temperature, UV index, pump status on misting system and drain level for my chameleon's terrarium to promote good health.

IOT Home Automation (Node MCU + BLYNK)
Intermediate
  • 5,205
  • 13

Control home appliances over internet. This IOT project done using Node MCU ESP8266 and BLYNK app. Control devices from anywhere.

Robot Arm Controlling with JavaScript
Intermediate
  • 611
  • 8

Full instructions

In this article, you will find out how to create a Robot Arm from a toy and how to program it with JavaScript.

Distinguish walking and running using Machine Learning
Intermediate
  • 2,704
  • 18

Full instructions

Gather data and develop algorithm to distinguish walking and running.

Add projectSign up / Login