Mahmoud Osman
Published © CC BY-NC-SA

Control your home devices using GLCD and Voice Recognition

Control your home devices using some button on the GLCD and using Voice Recognition

IntermediateWork in progress3,302
Control your home devices using GLCD and Voice Recognition

Things used in this project

Schematics

GLCD%20Shield_bb.png

GLCD Shield.fzz

Code

Untitled file

Arduino
#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

Mahmoud Osman

Mahmoud Osman

1 project • 2 followers
Student

Comments