Go Down

Topic: LCD clear (Read 1 time) previous topic - next topic

ted

Mar 09, 2018, 03:20 am Last Edit: Mar 09, 2018, 05:53 am by ted
How to implement the function -   lcd.clear(); activated by push button ?

 buttonState = digitalRead(buttonPin); //sample the state of the button - is it pressed or not?
 if( (buttonState == LOW);  // do LCD clear ?
 lcd.clear();


Code: [Select]


// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;
float  cur, acur[50], sumc;
const int buttonPin = PB4;
void setup()
{

  digitalWrite(buttonPin, HIGH);
  pinMode(PB4, INPUT_PULLUP);// button pin
  pinMode(PA7, INPUT);    // I2
  lcd.begin(16, 2);

  Serial.begin(9600);

  emon1.current(PA7, 2500);
}

void loop()
{
  emon1.calcVI(20, 2000);
  emon1.serialprint();

  float Irms = emon1.Irms;

  lcd.setCursor(0, 1);
  lcd.print("U=");
  lcd.print(Irms);

  lcd.setCursor(0, 0);
 lcd.print("H=");
  lcd.print(Irms );    // Value to be cleared when button is pressed


marco_c

A pushbutton is activated when it transitions from the off state (LOW OR HIGH, depends how the switch is wired) to the on state (HIGH or LOW). You need to remember what it was last time you checked and what it is now.

Mechanical switches also suffer from bounce, which will trigger the signal to go on and off a few times before it settles into the final state. There are lots of examples about eliminating bounce using either hardware or software methods.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

ted

Compiling error
Arduino: 1.8.3 (Windows Vista), Board: "Generic STM32F103C series, STM32F103C8 (20k
AC_meter_2LCD_b:24: error: expected initializer before 'void'

 void loop()

 ^

C:\Users\OWNER\Desktop\bibloteka\AC_meter_2LCD_b\AC_meter_2LCD_b.ino: In function 'void loop()':

AC_meter_2LCD_b:28: error: expected primary-expression before 'if'

     if( ( (buttonState == LOW);

     ^

AC_meter_2LCD_b:28: error: expected ')' before 'if'

AC_meter_2LCD_b:29: error: expected primary-expression before ')' token

  )

  ^

AC_meter_2LCD_b:29: error: expected ';' before ')' token

AC_meter_2LCD_b:43: error: expected unqualified-id before '(' token

 lcd.(Irms); // ?

     ^

Multiple libraries were found for "LiquidCrystal.h"
 Used: C:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\LiquidCrystal
 Not used: C:\Users\OWNER\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
 Not used: C:\Users\OWNER\Desktop\183\arduino-1.8.3\libraries\LiquidCrystal
Using library EmonLib at version 1.1.0 in folder: C:\Users\OWNER\Documents\Arduino\libraries\EmonLib
Using library LiquidCrystal in folder: C:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\LiquidCrystal (legacy)
exit status 1
expected initializer before 'void'


Code: [Select]
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;
float  cur, acur[50], sumc;
 int buttonState; // = digitalRead(buttonPin);
const int buttonPin = PB4;
int H
void setup()
{

  digitalWrite(buttonPin, HIGH);
  pinMode(PB4, INPUT_PULLUP);// button pin
  pinMode(PA7, INPUT);    // I2
  lcd.begin(16, 2);

  Serial.begin(9600);

  emon1.current(PA7, 2500);
}

void loop()
{
   buttonState = digitalRead(buttonPin);
 (
    if (buttonState == LOW);
 )
        // lcd.(Irms); // ?


     emon1.calcVI(20, 2000);
emon1.serialprint();

float Irms = emon1.Irms;

lcd.setCursor(0, 1);
lcd.print("U=");
lcd.print(Irms);

lcd.setCursor(0, 0);
lcd.(Irms); // ?
lcd.print("H=");
lcd.print(Irms );

}

ted

Thanks
Please look at last line of the code

TKall

int H

(
    if (buttonState == LOW);
 )

vaj4088

Well, for starters, this line

Code: [Select]

int H


is missing a semicolon, and

Code: [Select]

 (
    if (buttonState == LOW);
 )


does not do anything, and

Code: [Select]

lcd.(Irms); // ?


is just plain wrong and I don't know what was intended.


ted

Thanks
I made correction and new error is;

C:\Users\OWNER\Desktop\bibloteka\AC_meter_2LCD_b\AC_meter_2LCD_b.ino: In function 'void loop()':

AC_meter_2LCD_b:28: error: expected primary-expression before 'if'

     if (buttonState == LOW);

     ^

AC_meter_2LCD_b:28: error: expected ')' before 'if'

AC_meter_2LCD_b:31: error: 'Irms' was not declared in this scope

     lcd.clear(Irms);

               ^

AC_meter_2LCD_b:44: error: expected unqualified-id before '(' token

   lcd.(Irms); // ?

       ^

Multiple libraries were found for "LiquidCrystal.h"
 Used: C:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\LiquidCrystal
 Not used: C:\Users\OWNER\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
 Not used: C:\Users\OWNER\Desktop\183\arduino-1.8.3\libraries\LiquidCrystal
Using library EmonLib at version 1.1.0 in folder: C:\Users\OWNER\Documents\Arduino\libraries\EmonLib
Using library LiquidCrystal in folder: C:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\LiquidCrystal (legacy)
exit status 1
expected primary-expression before 'if'

Code: [Select]

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;
float  cur, acur[50], sumc;
int buttonState; // = digitalRead(buttonPin);
const int buttonPin = PB4;
int H;
void setup()
{

  digitalWrite(buttonPin, HIGH);
  pinMode(PB4, INPUT_PULLUP);// button pin
  pinMode(PA7, INPUT);    // I2
  lcd.begin(16, 2);

  Serial.begin(9600);

  emon1.current(PA7, 2500);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  (
    if (buttonState == LOW);
 
lcd.clear(Irms);


  emon1.calcVI(20, 2000);
  emon1.serialprint();

  float Irms = emon1.Irms;

  lcd.setCursor(0, 1);
  lcd.print("U=");
  lcd.print(Irms);

  lcd.setCursor(0, 0);
  lcd.(Irms); // ?
  lcd.print("H=");
  lcd.print(Irms );

}


TKall


ted

When button is pressed "Irms " value should be cleared

TKall

You were already told that this. if (buttonState == LOW);
Does nothing

ted

should do next line below - lcd.clear(Irms); or  clear(Irms); ?

marco_c

Code: [Select]
lcd.print(Irms );    // Value to be cleared when button is pressed
Your last line has no meaning to me.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

cheche_romo

then shouldn't it be:
Code: [Select]


if (buttonState == LOW)
{
  // When button state is low

  lcd.clear();
}
else
{
  // When button state is high

}



PaulMurrayCbr

When I see someone mangling the syntax of the language this badly, I usually suggest that they google "C++ tutorial" and do a C++ tutorial. You can't fix this kind of thing by fixing each error. You'll wind up with something that compiles but that does not do what you want.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

ted

#14
Mar 09, 2018, 03:06 pm Last Edit: Mar 09, 2018, 03:07 pm by ted
Thanks romo
I have no errors, now I will try to work on functionality of the program.

Code: [Select]

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;
float  cur, acur[50], sumc;
///////////////
int (clear);
int (Irms);
int buttonState; // = digitalRead(buttonPin);
const int buttonPin = PB4;
int H;
void setup()
{

  digitalWrite(buttonPin, HIGH);
  pinMode(PB4, INPUT_PULLUP);// button pin
  pinMode(PA7, INPUT);    // I2
  lcd.begin(16, 2);

  Serial.begin(9600);

  emon1.current(PA7, 2500);
}

void loop()
{ //////////////////////////////////////////
  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW)
  {
    // When button state is low

    lcd.clear();
  }
  else
  {
    // When button state is high

  }
  ////////////////////////////////////////////
  emon1.calcVI(20, 2000);
  emon1.serialprint();

  float Irms = emon1.Irms;

  lcd.setCursor(0, 1);
  lcd.print("U=");
  lcd.print(Irms);

  lcd.setCursor(0, 0);
  lcd.print("H=");
  lcd.print(Irms );

}


Go Up