This topic contains 10 replies, has 2 voices, and was last updated by avatar Amr 1 year, 1 month ago. This post has been viewed 388 times

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #118184
    avataryves.de
    Participant

    hi,
    i’m new to the all arduino world and would love to have a little push in the right direction.

    I m trying to command lights using GLCD,i managed so far to setup the screen and to turn them on and off with a few on and off button.

    The next step will be to dimm those lamps using two button for each lamps(one increase and one decrease)btw the lamp are led and i’ll use mosfet,i’m an electricien so my problem is more on the programing side.

    i tried and few things but i’m getting lost to even where to put the “loop”
    any help will be appreciated

    thanks

    yves

    my code

    [code]
    /*

    GLCD Shield Example

    This example shows an application on 1Sheeld’s GLCD shield.

    By using this example, you can draw a simple intreface for
    your home automation projects that consists of 3 buttons.

    OPTIONAL:
    To reduce the library compiled size and limit its memory usage, you
    can specify which shields you want to include in your sketch by
    defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.

    */

    #define CUSTOM_SETTINGS
    #define INCLUDE_GLCD_SHIELD

    /* Include 1Sheeld library. */
    #include <OneSheeld.h>

    int relayex = 5;
    bool exWasON = false;

    int relayfr = 6;
    bool frWasON = false;

    int relayfc = 7;
    bool fcWasON = false;

    int relayfl = 8;
    bool flWasON = false;

    int relaybc = 9;
    bool bcWasON = false;

    /* A name for the LED on pin 10. */
    int relayar = 10;
    bool arWasON = false;
    /* A name for the LED on pin 13. */
    int ledPin1 = 13;
    bool blWasON = false;

    /* A name for the LED on pin 12. */
    int ledPin2 = 12;
    bool alWasON = false;

    /* A name for the relay on pin 11. */
    int relayPin = 11;

    /* A variable that specify if the coffee machine was on. */
    bool puWasON = false;

    int relayPin1 = 14;

    bool boWasON = false;

    int relayBl1 = 15;

    bool brWasON = false;

    /* A variable that specify if the button is pressed at least once. */
    bool firstTimePressed = false;
    /* a name for relay pin 14 */

    /* Borders for the interface. */
    GLCDRectangle border1(0,0,255,127);
    GLCDRectangle border2(2,2,251,123);

    /* The three Buttons.*/
    GLCDButton lightButton1(3,3,45,30,”BL:ON”);
    GLCDButton lightButton2(53,3,45,30,”AL:ON”);
    GLCDButton pumpButton(102,3,45,30,”PU:ON”);
    GLCDButton light1Buttonup(3,33,22,30,”+”);
    GLCDButton light1Buttondown(25,33,22,30,”-“);
    GLCDButton light2Buttonup(53,33,22,30,”+”);
    GLCDButton light2Buttondown(75,33,22,30,”-“);
    GLCDButton boilerButton(102,95,45,30,”BO:ON”);
    GLCDButton backlight1Button(3,64,45,30,”BR:ON”);
    GLCDButton backlight1Buttonup(3,95,22,30,”+”);
    GLCDButton backlight1Buttondown(25,95,22,30,”-“);
    GLCDButton alcoverightButton(53,64,45,30,”AR:ON”);
    GLCDButton alcoverightButtonup(53,95,22,30,”+”);
    GLCDButton alcoverightButtondown(75,95,22,30,”-“);
    GLCDButton backcentreButton(102,33,45,30,”BC:ON”);
    GLCDButton backcentreButtonup(102,64,22,30,”+”);
    GLCDButton backcentreButtondown(125,64,22,30,”-“);
    GLCDButton frontleftButton(155,3,45,30,”FL:ON”);
    GLCDButton frontcentreButton(155,34,45,30,”FC:ON”);
    GLCDButton frontrightButton(155,64,45,30,”FR:ON”);
    GLCDButton extButton(208,3,45,30,”EX:ON”);
    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);
    pinMode(relayPin1,OUTPUT);
    pinMode(relayPin1,OUTPUT);
    pinMode(relayBl1,OUTPUT);
    pinMode(relayar,OUTPUT);
    pinMode(relayfl,OUTPUT);
    pinMode(relayfc,OUTPUT);
    pinMode(relayfr,OUTPUT);
    pinMode(relayex,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(pumpButton);
    GLCD.draw(light1Buttonup);
    GLCD.draw(light1Buttondown);
    GLCD.draw(light2Buttonup);
    GLCD.draw(light2Buttondown);
    GLCD.draw(boilerButton);
    GLCD.draw(backlight1Button);
    GLCD.draw(backlight1Buttonup);
    GLCD.draw(backlight1Buttondown);
    GLCD.draw(alcoverightButton);
    GLCD.draw(alcoverightButtonup);
    GLCD.draw(alcoverightButtondown);
    GLCD.draw(backcentreButton);
    GLCD.draw(backcentreButtonup);
    GLCD.draw(backcentreButtondown);
    GLCD.draw(frontleftButton);
    GLCD.draw(frontrightButton);
    GLCD.draw(frontcentreButton);
    GLCD.draw(extButton);

    }
    void setButtonTasks()
    {
    lightButton1.setOnChange(&button1Task);
    lightButton2.setOnChange(&button2Task);
    pumpButton.setOnChange(&pumpTask);
    boilerButton.setOnChange(&boilerButtonTask);
    backlight1Button.setOnChange(&backlight1ButtonTask);
    alcoverightButton.setOnChange(&alcoverightButtonTask);
    backcentreButton.setOnChange(&backcentreButtonTask);
    frontleftButton.setOnChange(&frontleftButtonTask);
    frontcentreButton.setOnChange(&frontcentreButtonTask);
    frontrightButton.setOnChange(&frontrightButtonTask);
    extButton.setOnChange(&extButtonTask);
    }

    void setButtonStyles()
    {
    lightButton1.setStyle(STYLE_3D);
    lightButton2.setStyle(STYLE_3D);
    pumpButton.setStyle(STYLE_3D);
    boilerButton.setStyle(STYLE_3D);
    backlight1Button.setStyle(STYLE_3D);
    alcoverightButton.setStyle(STYLE_3D);
    backcentreButton.setStyle(STYLE_3D);
    frontleftButton.setStyle(STYLE_3D);
    frontrightButton.setStyle(STYLE_3D);
    frontcentreButton.setStyle(STYLE_3D);
    extButton.setStyle(STYLE_3D);
    }

    void button1Task(bool button1State)
    {
    if(button1State)
    {
    if(firstTimePressed)
    {
    digitalWrite(ledPin1,LOW);
    lightButton1.setText(“BL:ON”);
    blWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(ledPin1,HIGH);
    lightButton1.setText(“BL:OFF”);
    blWasON = false;
    }
    }
    else if (!blWasON)
    {
    firstTimePressed = true;
    }
    }
    void button2Task(bool button2State)
    {
    if(button2State)
    {
    if(firstTimePressed)
    {
    digitalWrite(ledPin2,LOW);
    lightButton2.setText(“AL:ON”);
    alWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(ledPin2,HIGH);
    lightButton2.setText(“AL:OFF”);
    alWasON = false;
    }
    }
    else if (!alWasON)
    {
    firstTimePressed = true;
    }
    }

    void pumpTask(bool pumpButtonState)
    {
    if(pumpButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayPin,LOW);
    pumpButton.setText(“PU:ON”);
    puWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(relayPin,HIGH);
    pumpButton.setText(“PU:OFF”);
    puWasON = false;
    }
    }
    else if(!puWasON)
    {

    firstTimePressed = true;
    }
    }
    void boilerButtonTask(bool boilerButtonState)
    {
    if(boilerButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayPin1,LOW);
    boilerButton.setText(“BO:ON”);
    boWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayPin1,HIGH);
    boilerButton.setText(“BO:OFF”);
    boWasON = false;
    }
    }
    else if(!boWasON)
    {
    firstTimePressed = true;
    }
    }
    void backlight1ButtonTask(bool backlight1ButtonState)
    {
    if(backlight1ButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayBl1,LOW);
    backlight1Button.setText(“BR:ON”);
    brWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayBl1,HIGH);
    backlight1Button.setText(“BR:OFF”);
    brWasON = false;
    }
    }
    else if(!brWasON)
    {
    firstTimePressed = true;
    }
    }
    void alcoverightButtonTask(bool alcoverightButtonState)
    {
    if(alcoverightButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayar,LOW);
    alcoverightButton.setText(“AR:ON”);
    arWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayar,HIGH);
    alcoverightButton.setText(“AR:OFF”);
    arWasON = false;
    }
    }
    else if(!arWasON)
    {
    firstTimePressed = true;
    }
    }
    void backcentreButtonTask(bool backcentreButtonState)
    {
    if(backcentreButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relaybc,LOW);
    backcentreButton.setText(“BC:ON”);
    bcWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relaybc,HIGH);
    backcentreButton.setText(“BC:OFF”);
    brWasON = false;
    }
    }
    else if(!brWasON)
    {
    firstTimePressed = true;
    }
    }
    void frontleftButtonTask(bool frontleftButtonState)
    {
    if(frontleftButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayfl,LOW);
    frontleftButton.setText(“FL:ON”);
    flWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(relayfl,HIGH);
    frontleftButton.setText(“FL:OFF”);
    flWasON = false;
    }
    }
    else if(!flWasON)
    {
    firstTimePressed = true;
    }
    }
    void frontcentreButtonTask(bool frontcentreButtonState)
    {
    if(frontcentreButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayfc,LOW);
    frontcentreButton.setText(“FC:ON”);
    fcWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayfc,HIGH);
    frontcentreButton.setText(“FC:OFF”);
    fcWasON = false;
    }
    }
    else if(!fcWasON)
    {
    firstTimePressed = true;
    }
    }
    void frontrightButtonTask(bool frontrightButtonState)
    {
    if(frontrightButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayfr,LOW);
    frontrightButton.setText(“FR:ON”);
    frWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(relayfr,HIGH);
    frontrightButton.setText(“FR:OFF”);
    frWasON = false;
    }
    }
    else if(!frWasON)
    {
    firstTimePressed = true;
    }
    }
    void extButtonTask(bool extButtonState)
    {
    if(extButtonState)
    {
    if(firstTimePressed)
    {
    digitalWrite(relayex,LOW);
    extButton.setText(“EX:ON”);
    exWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayex,HIGH);
    extButton.setText(“EX:OFF”);
    exWasON = false;
    }
    }
    else if(!exWasON)
    {
    firstTimePressed = true;
    }
    }
    [/code]

    #120312
    avatarAmr
    Keymaster

    Hi,

    And welcome at 1Sheeld community 🙂

    First of all, I liked your – out of the box – idea of making a touch control panel with the phone’s screen! Ideas like this are what really make 1Sheeld’s creations go beyond stars!

    For your code, really well done! You are making a great progress here in Arduino coding and let me explain how you can (dim) an LED with Arduino.

    This is done using the PWM concept which I recommend you check this tutorial to get an understanding of it.

    Then, I have applied this on (pin 11) because it’s one of the pins that marked with the sign (~) which means you can out analog voltage on it, other than the steady 5V or 0V. Did you get it?

    So, check the updated code with a pin 11 connected LED and play with the first (+) and (-) buttons on the GLCD screen and you are going to see the magic happens 🙂 .. which you can repeat in your code for all other connected LEDs.

    Note: I have noticed that you are using pin 11 for a relay but I have connected an LED on it .. doesn’t matter since you get the concept understood. Of course, the next step is to connect the LED to a mosfet and the mosfet to the Arduino pin directly, as you have mentioned in your post.

    Give it a try and let me updated with your results to get your awesome project achieved 🙂

    Code:

    #134172
    avataryves.de
    Participant

    hi,
    thank you very much for your help, it worked like a charm,as all project,it did grow and evolved,after the lights, i m trying to control a fan.

    i configured all the button on the glcd fine and managed to make it work through some relay,my only concern is that it has three speeds contoled by the three button (1,2,3) i’m a bit lost about how to managed to use only one speed at the time

    as an example if i start by pressing button 1 ,the fan start on low speed,if i want to go faster i ll press the button 2, and it should shut the button 1,that just the blocking the button 1 part that i’m missing(and the button 2 when i want to go to speed 3 …and the 3 when i want to go back to 1 …. :))

    if you could giveme some advise i ll appreciate it

    thankx

    yves

    [code]

    /*

    #define CUSTOM_SETTINGS
    #define INCLUDE_GLCD_SHIELD

    /* Include 1Sheeld library. */
    #include <OneSheeld.h>

    int relayex = 5;
    bool exWasON = false;

    int relayfr = 9;
    bool frWasON = false;

    int relayfc = 7;
    bool fcWasON = false;

    int relayfl = 3;
    bool flWasON = false;

    int relaybc = 6;
    bool bcWasON = false;

    /* A name for the LED on pin 10. */
    int relayar = 10;
    bool arWasON = false;

    /* A name for the LED on pin 13. */
    int ledPin1 = 13;
    bool blWasON = false;

    /* A name for the LED on pin 12. */
    int ledPin2 = 12;
    bool alWasON = false;

    /* A name for the relay on pin 11. */
    int relayPin = 11;
    bool puWasON = false;

    int relayPin1 = 4;
    bool boWasON = false;

    int relayBl1 = 8;
    bool brWasON = false;

    int relayve = A3;
    bool veWasON = false;

    int ve1 = A2;
    bool ve1WasON = false;

    int ve2 = A4;
    bool ve2WasON = false;

    int ve3 = A5;
    bool ve3WasON = false;

    /* A variable that specify if the button is pressed at least once. */
    bool firstTimePressed = false;
    /* a name for relay pin 14 */

    /* Borders for the interface. */
    GLCDRectangle border1(0, 0, 255, 127);
    GLCDRectangle border2(2, 2, 251, 123);

    /* The three Buttons.*/
    GLCDButton lightButton1(3, 3, 45, 30, “BL: ON”);
    GLCDButton lightButton2(53, 3, 45, 30, “AL: ON”);
    GLCDButton pumpButton(102, 3, 45, 30, “PU: ON”);
    GLCDButton light1Buttonup(3, 33, 22, 30, ” +”);
    GLCDButton light1Buttondown(25, 33, 22, 30, ” -“);
    GLCDButton light2Buttonup(53, 33, 22, 30, ” +”);
    GLCDButton light2Buttondown(75, 33, 22, 30, ” -“);
    GLCDButton boilerButton(102, 95, 45, 30, “BO: ON”);
    GLCDButton backlight1Button(3, 64, 45, 30, “BR: ON”);
    GLCDButton backlight1Buttonup(3, 95, 22, 30, ” +”);
    GLCDButton backlight1Buttondown(25, 95, 22, 30, ” -“);
    GLCDButton alcoverightButton(53, 64, 45, 30, “AR: ON”);
    GLCDButton alcoverightButtonup(53, 95, 22, 30, ” +”);
    GLCDButton alcoverightButtondown(75, 95, 22, 30, ” -“);
    GLCDButton backcentreButton(102, 33, 45, 30, “BC: ON”);
    GLCDButton backcentreButtonup(102, 64, 22, 30, ” +”);
    GLCDButton backcentreButtondown(125, 64, 22, 30, ” -“);
    GLCDButton frontleftButton(208, 34, 45, 30, “FL: ON”);
    GLCDButton frontcentreButton(155, 34, 45, 30, “FC: ON”);
    GLCDButton frontrightButton(155, 95, 45, 30, “FR: ON”);
    GLCDButton extButton(208, 95, 45, 30, “EX: ON”);
    GLCDButton veButton(155, 3, 45, 30, “VE: ON”);
    GLCDButton ve1Button(201, 3, 17, 30, “1”);
    GLCDButton ve2Button(219, 3, 17, 30, “2”);
    GLCDButton ve3Button(236, 3, 17, 30, “3”);

    int light1_counter = 0;

    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);
    pinMode(relayPin1, OUTPUT);
    pinMode(relayPin1, OUTPUT);
    pinMode(relayBl1, OUTPUT);
    pinMode(relayar, OUTPUT);
    pinMode(relayfl, OUTPUT);
    pinMode(relayfc, OUTPUT);
    pinMode(relayfr, OUTPUT);
    pinMode(relayex, OUTPUT);
    pinMode(relaybc, OUTPUT);
    pinMode(relayve, OUTPUT);
    pinMode(ve1, OUTPUT);
    pinMode(ve2, OUTPUT);
    pinMode(ve3, 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(pumpButton);
    GLCD.draw(light1Buttonup);
    GLCD.draw(light1Buttondown);
    GLCD.draw(light2Buttonup);
    GLCD.draw(light2Buttondown);
    GLCD.draw(boilerButton);
    GLCD.draw(backlight1Button);
    GLCD.draw(backlight1Buttonup);
    GLCD.draw(backlight1Buttondown);
    GLCD.draw(alcoverightButton);
    GLCD.draw(alcoverightButtonup);
    GLCD.draw(alcoverightButtondown);
    GLCD.draw(backcentreButton);
    GLCD.draw(backcentreButtonup);
    GLCD.draw(backcentreButtondown);
    GLCD.draw(frontleftButton);
    GLCD.draw(frontrightButton);
    GLCD.draw(frontcentreButton);
    GLCD.draw(extButton);
    GLCD.draw(veButton);
    GLCD.draw(ve1Button);
    GLCD.draw(ve2Button);
    GLCD.draw(ve3Button);
    }
    void setButtonTasks()
    {
    lightButton1.setOnChange(&button1Task);
    lightButton2.setOnChange(&button2Task);
    pumpButton.setOnChange(&pumpTask);
    boilerButton.setOnChange(&boilerButtonTask);
    backlight1Button.setOnChange(&backlight1ButtonTask);
    alcoverightButton.setOnChange(&alcoverightButtonTask);
    backcentreButton.setOnChange(&backcentreButtonTask);
    frontleftButton.setOnChange(&frontleftButtonTask);
    frontcentreButton.setOnChange(&frontcentreButtonTask);
    frontrightButton.setOnChange(&frontrightButtonTask);
    extButton.setOnChange(&extButtonTask);
    light1Buttonup.setOnChange(&up1ButtonTask);
    light1Buttondown.setOnChange(&down1ButtonTask);
    light2Buttonup.setOnChange(&light2ButtonupTask);
    light2Buttondown.setOnChange(&light2ButtondownTask);
    backlight1Buttonup.setOnChange(&backlight1ButtonupTask);
    backlight1Buttondown.setOnChange(&backlight1ButtondownTask);
    alcoverightButtonup.setOnChange(&alcoverightButtonupTask);
    alcoverightButtondown.setOnChange(&alcoverightButtondownTask);
    backcentreButtonup.setOnChange(&backcentreButtonupTask);
    backcentreButtondown.setOnChange(&backcentreButtonupTask);
    veButton.setOnChange(&veButtonTask);
    ve1Button.setOnChange(&ve1ButtonTask);
    ve2Button.setOnChange(&ve2ButtonTask);
    ve3Button.setOnChange(&ve3ButtonTask);

    }

    void setButtonStyles()
    {
    lightButton1.setStyle(STYLE_3D);
    lightButton2.setStyle(STYLE_3D);
    pumpButton.setStyle(STYLE_3D);
    boilerButton.setStyle(STYLE_3D);
    backlight1Button.setStyle(STYLE_3D);
    alcoverightButton.setStyle(STYLE_3D);
    backcentreButton.setStyle(STYLE_3D);
    frontleftButton.setStyle(STYLE_3D);
    frontrightButton.setStyle(STYLE_3D);
    frontcentreButton.setStyle(STYLE_3D);
    extButton.setStyle(STYLE_3D);
    veButton.setStyle(STYLE_3D);

    }
    void ve3ButtonTask(bool ve3ButtonState)
    {
    if (ve3ButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(ve3, LOW);
    ve3Button.setText(“3”);
    ve3WasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(ve3, HIGH);
    ve3Button.setText(“30”);
    ve3WasON = false;

    }

    }
    else if (!ve3WasON)
    {
    firstTimePressed = true;
    }
    }
    void ve2ButtonTask(bool ve2ButtonState)
    {
    if (ve2ButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(ve2, LOW);
    ve2Button.setText(“2”);
    ve2WasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(ve2, HIGH);
    ve2Button.setText(“20”);
    ve2WasON = false;
    }
    }
    else if (!ve2WasON)
    {
    firstTimePressed = true;
    }
    }
    void ve1ButtonTask(bool ve1ButtonState)
    {
    if (ve1ButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(ve1, LOW);
    ve1Button.setText(“1”);
    ve1WasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(ve1, HIGH);
    ve1Button.setText(“10”);
    ve1WasON = false;
    }
    }
    else if (!ve1WasON)
    {
    firstTimePressed = true;
    }
    }
    void veButtonTask(bool veButtonState)
    {
    if (veButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayve, LOW);
    veButton.setText(“VE: ON”);
    veWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayve, HIGH);
    veButton.setText(“VE: OFF”);
    veWasON = false;
    }
    }
    else if (!veWasON)
    {
    firstTimePressed = true;
    }
    }
    void button1Task(bool button1State)
    {
    if (button1State)
    {
    if (firstTimePressed)
    {
    digitalWrite(ledPin1, LOW);
    lightButton1.setText(“BL: ON”);
    blWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(ledPin1, HIGH);
    lightButton1.setText(“BL: OFF”);
    blWasON = false;
    }
    }
    else if (!blWasON)
    {
    firstTimePressed = true;
    }
    }
    void button2Task(bool button2State)
    {
    if (button2State)
    {
    if (firstTimePressed)
    {
    digitalWrite(ledPin2, LOW);
    lightButton2.setText(“AL: ON”);
    alWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(ledPin2, HIGH);
    lightButton2.setText(“AL: OFF”);
    alWasON = false;
    }
    }
    else if (!alWasON)
    {
    firstTimePressed = true;
    }
    }

    void pumpTask(bool pumpButtonState)
    {
    if (pumpButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayPin, LOW);
    pumpButton.setText(“PU: ON”);
    puWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(relayPin, HIGH);
    pumpButton.setText(“PU: OFF”);
    puWasON = false;
    }
    }
    else if (!puWasON)
    {

    firstTimePressed = true;
    }
    }
    void boilerButtonTask(bool boilerButtonState)
    {
    if (boilerButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayPin1, LOW);
    boilerButton.setText(“BO: ON”);
    boWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayPin1, HIGH);
    boilerButton.setText(“BO: OFF”);
    boWasON = false;
    }
    }
    else if (!boWasON)
    {
    firstTimePressed = true;
    }
    }
    void backlight1ButtonTask(bool backlight1ButtonState)
    {
    if (backlight1ButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayBl1, LOW);
    backlight1Button.setText(“BR: ON”);
    brWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayBl1, HIGH);
    backlight1Button.setText(“BR: OFF”);
    brWasON = false;
    }
    }
    else if (!brWasON)
    {
    firstTimePressed = true;
    }
    }
    void alcoverightButtonTask(bool alcoverightButtonState)
    {
    if (alcoverightButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayar, LOW);
    alcoverightButton.setText(“AR: ON”);
    arWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayar, HIGH);
    alcoverightButton.setText(“AR:OFF”);
    arWasON = false;
    }
    }
    else if (!arWasON)
    {
    firstTimePressed = true;
    }
    }
    void backcentreButtonTask(bool backcentreButtonState)
    {
    if (backcentreButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relaybc, LOW);
    backcentreButton.setText(“BC: ON”);
    bcWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relaybc, HIGH);
    backcentreButton.setText(“BC: OFF”);
    brWasON = false;
    }
    }
    else if (!brWasON)
    {
    firstTimePressed = true;
    }
    }
    void frontleftButtonTask(bool frontleftButtonState)
    {
    if (frontleftButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayfl, LOW);
    frontleftButton.setText(“FL: ON”);
    flWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(relayfl, HIGH);
    frontleftButton.setText(“FL: OFF”);
    flWasON = false;
    }
    }
    else if (!flWasON)
    {
    firstTimePressed = true;
    }
    }
    void frontcentreButtonTask(bool frontcentreButtonState)
    {
    if (frontcentreButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayfc, LOW);
    frontcentreButton.setText(“FC: ON”);
    fcWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayfc, HIGH);
    frontcentreButton.setText(“FC: OFF”);
    fcWasON = false;
    }
    }
    else if (!fcWasON)
    {
    firstTimePressed = true;
    }
    }
    void frontrightButtonTask(bool frontrightButtonState)
    {
    if (frontrightButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayfr, LOW);
    frontrightButton.setText(“FR: ON”);
    frWasON = true;
    firstTimePressed = false;

    }
    else
    {
    digitalWrite(relayfr, HIGH);
    frontrightButton.setText(“FR: OFF”);
    frWasON = false;
    }
    }
    else if (!frWasON)
    {
    firstTimePressed = true;
    }
    }
    void extButtonTask(bool extButtonState)
    {
    if (extButtonState)
    {
    if (firstTimePressed)
    {
    digitalWrite(relayex, LOW);
    extButton.setText(“EX: ON”);
    exWasON = true;
    firstTimePressed = false;
    }
    else
    {
    digitalWrite(relayex, HIGH);
    extButton.setText(“EX: OFF”);
    exWasON = false;
    }
    }
    else if (!exWasON)
    {
    firstTimePressed = true;
    }
    }

    void up1ButtonTask ()
    {
    light1_counter = light1_counter + 10;

    // make sure that value on the LED doesn’t exceed 255
    if( light1_counter > 250 )
    {
    light1_counter = 250;
    }

    if (blWasON == false)analogWrite(ledPin1 , light1_counter);
    }

    void down1ButtonTask()
    {
    light1_counter = light1_counter – 10;

    // make sure that value on the LED doesn’t go below 0
    if( light1_counter < 0 )
    {
    light1_counter = 0;
    }

    if (blWasON == false)analogWrite(ledPin1 , light1_counter);
    }
    void light2ButtonupTask ()
    {
    light1_counter = light1_counter + 10;

    // make sure that value on the LED doesn’t exceed 255
    if( light1_counter > 250 )
    {
    light1_counter = 250;
    }

    if (alWasON == false)analogWrite(ledPin2 , light1_counter);
    }

    void light2ButtondownTask()
    {
    light1_counter = light1_counter – 10;

    // make sure that value on the LED doesn’t go below 0
    if( light1_counter < 0 )
    {
    light1_counter = 0;
    }

    if (alWasON == false) analogWrite(ledPin2 , light1_counter);
    }
    void backlight1ButtonupTask ()
    {
    light1_counter = light1_counter + 10;

    // make sure that value on the LED doesn’t exceed 255
    if( light1_counter > 250 )
    {
    light1_counter = 250;
    }

    if (brWasON == false)analogWrite(relayBl1 , light1_counter);
    }

    void backlight1ButtondownTask()
    {
    light1_counter = light1_counter – 10;

    // make sure that value on the LED doesn’t go below 0
    if( light1_counter < 0 )
    {
    light1_counter = 0;
    }

    if (brWasON == false)analogWrite(relayBl1, light1_counter);
    }

    void alcoverightButtonupTask ()
    {
    light1_counter = light1_counter + 10;

    // make sure that value on the LED doesn’t exceed 255
    if( light1_counter > 250 )
    {
    light1_counter = 250;
    }

    if (arWasON == false)analogWrite(relayar , light1_counter);
    }

    void alcoverightButtondownTask()
    {
    light1_counter = light1_counter – 10;

    // make sure that value on the LED doesn’t go below 0
    if( light1_counter < 0 )
    {
    light1_counter = 0;
    }

    if (arWasON == false)analogWrite(relayar, light1_counter);
    }
    void backcentreButtonupTask ()
    {
    light1_counter = light1_counter + 10;

    // make sure that value on the LED doesn’t exceed 255
    if( light1_counter > 250 )
    {
    light1_counter = 250;
    }

    if (bcWasON == false)analogWrite(relaybc , light1_counter);
    }

    void backcentreButtondownTask ()
    {
    light1_counter = light1_counter – 10;

    // make sure that value on the LED doesn’t go below 0
    if( light1_counter < 0 )
    {
    light1_counter = 0;
    }

    if (bcWasON == false)analogWrite(relaybc, light1_counter);
    }

    #134181
    avatarAmr
    Keymaster

    Hi,

    Since you are making a speed control and needs a group of buttons which selecting one MUST deselect all others, then You can use the Radio Buttons instead of normal buttons. Like that:

    GLCDRadioButton rdbutton(0,0,”1Sheeld”);

    And make use of this function to remove the select of any radio button and select a certain radio button:

    rdButton.select();


    And one tricky thing to do is to use a bool variable that changes between true & false whenever a speed button is selected/deselected. Please refer to the GLCD Shield Documentation for more information.

    #135077
    avataryves.de
    Participant

    hi,
    i read the doc but it’s way above my skills,the sketches found on radiobutton in your library are giving me errors,i will need an example of some glcdradiobutton sketch that i can play with to understand how it works

    thx

    #135347
    avatarAmr
    Keymaster

    Okay,

    Here’s a code snippet of the project I am working on and will publish soon .. I have used the GLCD radio buttons functionalities to select from different modes for my robot … so, here’s what you will do for example, to make 2 radio buttons:

    Write this code above the “void setup()”

    And write this code inside the “void setup()”

    And write this code below and outside the “void loop()”

    And don’t forget to reset the Arduino from its reset button just after you connect 1Sheeld to the phone App and select the GLCD shield

    #138263
    avataryves.de
    Participant

    thx for the help,
    didn’t have time to look at your code yet,but i went for a test drive with my GLCD project(the lighting of my campervan) and two question arose
    first can we connect two phones on 1sheeld (mine and my girlfriend) so we both can control the light from our own phone?
    second is there any way around the fact that,every time i go out of my van, i need to manualy press the reset button when i m back to get my GLCD on my phone(my arduino been hidden in a drawer it’s a bit of a pain)?

    #138301
    avatarAmr
    Keymaster

    Hi,

    Actually, 1Sheeld board can only be connected to one App at the time.

    And definitely, you can reset the Arduino with software without pressing the Arduino physical reset button and do it as follows:

    above the void setup()
    int resetPin = 12;

    In the void setup():

    And connect the pin 12 with a wire to the reset pin. Then use any button-like shield, maybe the pushbutton shield to reset the Arduino. Note: reseting the Arduino means to make the resetPin LOW then back it to HIGH again. Like:

    Try it and let me know if this helps …

    #159687
    avataryves.de
    Participant

    hi,
    tried the push button code but the reset is going on a loop ,the Glcd reset every second over and over,if i put a led on the pin 12 the push button work(led always on exept when push button pressed),
    and if i put a mechanical push button between GND and reset pin the Glcd is reseting
    i will go the mechanical solution by putting a push button somewhere in my van

    thank you

    #159901
    avataryves.de
    Participant

    hi,
    found the bug,the digital write should happen before the pin mode…
    i did managed the radio button sketch too will try it all next week end

    thx

    #167192
    avatarAmr
    Keymaster

    Hi,

    Sooooooory, but don’t do this option as by trying and error, I have just discovered that it’s not reliable.

    Try this solution which has been tested from my side with my latest project here. It’s easy, just copy-paste this code inside the void loop()

    And this code above and outside the void setup()
    void(* resetFunc) (void) = 0;

    And of course you will use the push button to reset the Arduino. Give it a try and let me know the updates ….

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.