Author Topic: How to stop flickering of LCD using Arduino Code?  (Read 9059 times)

0 Members and 1 Guest are viewing this topic.

Offline radhikaTopic starter

  • Regular Contributor
  • *
  • Posts: 105
  • Country: in
How to stop flickering of LCD using Arduino Code?
« on: June 09, 2018, 06:46:54 pm »
Hello,
I am new to Arduino coding. I have developed a menu code where 5V 1A, 5V 2A, 5V 3A are a different option. These options get ON and OFF with the help of 3 buttons which is UP, DOWN and SELECT.
The LCD displays correct output in Proteus, but it flickers a lot. I am unable to get the stable output. Please guide me.

Here is the attached code:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int menuitem = 1;
int page = 1;

int oneamp = 6;    // This is the output pins
int twoamp = 7;
int threeamp = 8;


volatile boolean up = false;   //BUTTON
volatile boolean down = false;
volatile boolean select = false;

int downButtonState = 0;
int upButtonState = 0; 
int selectButtonState = 0;         
int lastDownButtonState = 0;
int lastSelectButtonState = 0;
int lastUpButtonState = 0;

void setup() {
  lcd.begin(16, 2); 
  lcd.setCursor(1,0);
  pinMode(9, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(oneamp, OUTPUT);
  pinMode(twoamp, OUTPUT);
  pinMode(threeamp, OUTPUT);

  Serial.begin(9600);
 
     
   
}

void loop() {
 
  drawMenu();

  downButtonState = digitalRead(1);
  selectButtonState = digitalRead(0);
  upButtonState =   digitalRead(9);

  oneamp = digitalRead(6);
  twoamp = digitalRead(7);
  threeamp = digitalRead(8);
 
  checkIfDownButtonIsPressed();
  checkIfUpButtonIsPressed();
  checkIfSelectButtonIsPressed();

  if (up == 1 )
  {
    up = false;
    menuitem--;
    if (menuitem==0)
    {
      menuitem=3;
      {
      if (select = 1)
      {
        digitalWrite( oneamp, HIGH );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );
        }
      else
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );
       }
    }
     
    }     
  }


 if (down == 1 )
  {
    down = false;
    menuitem++;
    if (menuitem==4)
    {
      menuitem=1;
      {
      if (select = 1)
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, HIGH );
        digitalWrite( threeamp, LOW );
        }
      else
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );
       }
    }
     
    }     
  }


 if (menuitem == 5 )
    {
      menuitem=2;
      {
      if (select = 1)
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, HIGH );
        }
      else
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );
       }
    }
     
    }     
  }

  void checkIfDownButtonIsPressed()
  {
    if (downButtonState != lastDownButtonState)
  {
    if (downButtonState == 0)
    {
      down=true;
    }
    delay(50);
  }
   lastDownButtonState = downButtonState;
  }

void checkIfUpButtonIsPressed()
{
  if (upButtonState != lastUpButtonState)
  {
    if (upButtonState == 0) {
      up=true;
    }
    delay(50);
  }
   lastUpButtonState = upButtonState;
}

void checkIfSelectButtonIsPressed()
{
   if (selectButtonState != lastSelectButtonState)
  {
    if (selectButtonState == 0) {
      select=true;
    }
    delay(50);
  }
   lastSelectButtonState = selectButtonState;
}

 
  void drawMenu()
  {
   
  if (page==1)
  {   
    lcd.clear();
   
    lcd.setCursor(1, 0);
    lcd.print("MAIN MENU");
   
   
   
    if (menuitem==1)
  {
   
    lcd.setCursor(1, 1);
    lcd.print(">5V 1A:");
    if (select = 1)
    {
      lcd.print("ON");
    }
    else
    {
      lcd.print("OFF");
    }
  }
   
    if (menuitem==2)
    {
     
      lcd.setCursor(1, 2);
      lcd.print(">5V 2A: ");
   
   
    if (select = 1)
    {
      lcd.print("ON");
    }
    else
    {
      lcd.print("OFF");
    }
   }

   
    if (menuitem==3)
    {
    lcd.setCursor(1, 3);
    lcd.print(">5V 3A:");
    if (select = 1)
    {
      lcd.print("ON");
    }
    else
    {
      lcd.print("OFF");
    }
   }

  }
  }
 
 




 

Offline dmills

  • Super Contributor
  • ***
  • Posts: 2093
  • Country: gb
Re: How to stop flickering of LCD using Arduino Code?
« Reply #1 on: June 09, 2018, 06:56:49 pm »
Horrible code, but anyway, you only want to redraw the LCD if something has changed, so do something like

int redraw = 1;

then in the main loop :

if (redraw){
    drawMenu();
    redraw = 0;
}

Then in your button handlers set redraw to 1 if a button has been pressed.

Regards, Dan.



 
The following users thanked this post: radhika

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: How to stop flickering of LCD using Arduino Code?
« Reply #2 on: June 09, 2018, 07:21:53 pm »
I won't give you a solution because this is a very good learning problem and you will like it better when you figure it out yourself. But I will give you a few hints:


* Why does an LCD flicker? (let's assume there are no hardware faults) Flicker usually means rapid changing between the pixels being on and off. Try to think about what in your code could make this happen.

* Once you figure out the above, try to identify where in your code you are making the pixels flip back and forth.

* Also keep in mind that these small LCDs are not like computer screens where you can afford to wipe the entire screen on every "frame" and draw from scratch. There is no double buffering neither and the display is rather slow, you may actually have to wait for it to finish whatever it is doing before you attempt to send another thing to it instead of "blasting" it with data in a loop.

So you may want to rethink you approach.
 

Offline radhikaTopic starter

  • Regular Contributor
  • *
  • Posts: 105
  • Country: in
Re: How to stop flickering of LCD using Arduino Code?
« Reply #3 on: June 09, 2018, 07:30:21 pm »
Hello,
I have added the required redraw in main loop. I have checked the result but it still flickers.
 

Offline Cyberdragon

  • Super Contributor
  • ***
  • Posts: 2676
  • Country: us
Re: How to stop flickering of LCD using Arduino Code?
« Reply #4 on: June 09, 2018, 07:46:42 pm »
Horrible code, but anyway, you only want to redraw the LCD if something has changed, so do something like

int redraw = 1;

then in the main loop :

if (redraw){
    drawMenu();
    redraw = 0;
}

Then in your button handlers set redraw to 1 if a button has been pressed.

Regards, Dan.

Int? Don't you mean boolean?
*BZZZZZZAAAAAP*
Voltamort strikes again!
Explodingus - someone who frequently causes accidental explosions
 

Offline dmills

  • Super Contributor
  • ***
  • Posts: 2093
  • Country: gb
Re: How to stop flickering of LCD using Arduino Code?
« Reply #5 on: June 10, 2018, 01:22:15 am »
Ick, C++, yea bool, but really whatever, it is not the worst thing in that code.

Regards, Dan.
 

Online Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: How to stop flickering of LCD using Arduino Code?
« Reply #6 on: June 10, 2018, 01:53:43 am »
Those simple LCD's really are slow enough for the eye to perceive changes, so screen clears are going to be visible in the general case. Also, I suggest that you use actual hardware before deciding what's acceptable. Hardware simulations are not perfect.

For your specific case, I suggest commenting out the lcd.clear entirely. Then change "ON" to "ON " in all places. That way "ON " and "OFF" have the same number of characters and will overwrite one another completely when they get changed. You should no longer NEED to clear the screen unless you change to a completely different menu. That should eliminate the flicker effect.
 

Offline Monkeh

  • Super Contributor
  • ***
  • Posts: 7992
  • Country: gb
Re: How to stop flickering of LCD using Arduino Code?
« Reply #7 on: June 10, 2018, 02:19:29 am »
Ick, C++, yea bool, but really whatever, it is not the worst thing in that code.

Regards, Dan.

We've had boolean in C for nearly 20 years. It's not 1972 any more.
 
The following users thanked this post: newbrain

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: How to stop flickering of LCD using Arduino Code?
« Reply #8 on: June 10, 2018, 03:38:05 am »
Might want to fix this first:
Code: [Select]
if (select = 1)
Agree with the others here, this is horrible code. There is an excruciating amount of duplication. Also, responding to buttons and changing the settings should be done in an interrupt handler, since there's nothing to be done "in the background", and the MCU should be just halted waiting for an interrupt the majority of the time.

Learn to do the above, use the ?: operator, and simplify your code by removing/refactoring repeated pieces. That will get you 90% of the way to a good solution.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: How to stop flickering of LCD using Arduino Code?
« Reply #9 on: June 10, 2018, 10:27:22 am »
I just love how everyone is lecturing the poor newbie about how bad and horrible the code is (it is) but nobody actually answers their question ...   :palm:

Hello,
I have added the required redraw in main loop. I have checked the result but it still flickers.

Of course it does flicker.

The problem is that you are clearing the display and redrawing it from scratch on every iteration of the main loop (the loop() function). Don't do that!


The display isn't fast enough to update that quickly, so you will have weird artifacts, flicker and what not. It may even crash the display controller (depends on whether or not the LCD library actually waits for the ready signal from the LCD/you have it connected). It is also a terrible approach from the power consumption point of view because the MCU is constantly busy looping and blasting data into the LCD even when nothing is changing (no buttons are being pressed).

The proper way to do this is to redraw the display (either fully or partially) only when the user presses a button and you need to actually change something. That can be done in various ways - e.g. using an interrupt to read the buttons and triggering the redrawing there, polling the buttons in the loop() and redrawing the display only when a button was pressed and not every time.


The button debouncing code - don't put delay() there, that will just slow down the entire processing. If you don't want to implement your own debouncer, the Bounce2 library is a good choice for doing it for you:
https://github.com/thomasfredericks/Bounce2

If you want to make your own debouncer, then this series is a great start (the actual debouncers are in the part two linked at the bottom):
http://www.ganssle.com/debouncing.htm


 
The following users thanked this post: radhika

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: How to stop flickering of LCD using Arduino Code?
« Reply #10 on: June 10, 2018, 10:46:55 am »
so tldr:
redraw lcd only if stuff actually changes
for debouncing consider using a ceramic capacitor and a resistor, they're cheap and you basically get hw debounce.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: How to stop flickering of LCD using Arduino Code?
« Reply #11 on: June 10, 2018, 11:51:14 am »
for debouncing consider using a ceramic capacitor and a resistor, they're cheap and you basically get hw debounce.


That's actually a fairly terrible idea and doesn't work properly. Even if the MCU has Schmitt trigger inputs (most don't) it still has issues - check the article I have linked above for explanation why (http://www.ganssle.com/debouncing-pt2.htm) and how to make it work if you really want to use this type of solution.
« Last Edit: June 10, 2018, 12:03:27 pm by janoc »
 

Offline PlainName

  • Super Contributor
  • ***
  • Posts: 6844
  • Country: va
Re: How to stop flickering of LCD using Arduino Code?
« Reply #12 on: June 10, 2018, 02:44:13 pm »
As world+dog has pointed out, clearing the screen every time you do something is going to cause flicker. A pretty decent fix for this particular project is the one where ON and OFF are the same length (i.e. 'ON ' and 'OFF') then you can just write the correct one in place when needed and it'll overwrite the unwanted one without any screen clearing.

However, that won't help in projects where the screen display isn't so simple or convenient. There is also the issue of having to slow down to the screens input speed.

What I would do is double-buffer the display. That is, have a copy of the display in memory and all the functions write to that. The physical display is then updated from the virtual one (either in a loop or via a timer) and only changes are copied, so there is no flickering, no waiting for the display to catch up, and because the physical display writes are minimal it's jolly fast. There are other advantages too, but it'd be too tedious to list them all :)
 

Online Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: How to stop flickering of LCD using Arduino Code?
« Reply #13 on: June 10, 2018, 03:11:40 pm »
I just love how everyone is lecturing the poor newbie about how bad and horrible the code is (it is) but nobody actually answers their question ...   :palm:

Including yourself. I love how people fail to read prior responses. Pretty sure I answered the actual question above, without criticizing the code.
 
The following users thanked this post: radhika

Offline tsman

  • Frequent Contributor
  • **
  • Posts: 599
  • Country: gb
Re: How to stop flickering of LCD using Arduino Code?
« Reply #14 on: June 10, 2018, 03:21:35 pm »
int oneamp = 6;    // This is the output pins
int twoamp = 7;
int threeamp = 8;

You're using the oneamp/twoamp/threeamp variables to store the pin number for later calls to digitalWrite but then you overwrite those variables with 0/1 with digitalRead. Take out these 3 digitalRead calls.

  oneamp = digitalRead(6);
  twoamp = digitalRead(7);
  threeamp = digitalRead(8);

  if (select = 1)
As amyk pointed out, these lines are wrong. You're actually assigning 1 to select. You need to do == to test for equality.
« Last Edit: June 10, 2018, 03:26:17 pm by tsman »
 
The following users thanked this post: radhika

Offline radhikaTopic starter

  • Regular Contributor
  • *
  • Posts: 105
  • Country: in
Re: How to stop flickering of LCD using Arduino Code?
« Reply #15 on: June 10, 2018, 04:53:56 pm »
Hello there,
I know it's horrible code. But, for me it is an excellent one :-//. I learnt Arduino so quick and code long one.
I found the error, that I just need to remove lcd.clear().
Thank You for guidance and help. :)

#a5
Radhika Das
 

Offline radhikaTopic starter

  • Regular Contributor
  • *
  • Posts: 105
  • Country: in
Re: How to stop flickering of LCD using Arduino Code?
« Reply #16 on: June 10, 2018, 08:06:19 pm »
I have redraw the code, here it won't flicker anymore. But, when I press rewuired button to select let say 5V 1A, it won't turn ON LED attached to it. Here is the code:

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int menuitem = 1;
int page = 1;

boolean oneamp = false;
boolean twoamp = false;
boolean threeamp = false;

int oneampState = 0;
int twoampState = 0;
int threeampState = 0;


volatile boolean up = false;
volatile boolean down = false;
volatile boolean select = false;

int downButtonState = 0;
int upButtonState = 0; 
int selectButtonState = 0;         
int lastDownButtonState = 0;
int lastSelectButtonState = 0;
int lastUpButtonState = 0;

void setup() {
  lcd.clear();
  lcd.begin(16, 2); 
  lcd.setCursor(1,0);
  pinMode(9, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
 
  Serial.begin(9600); 
}

void loop() {
 
  drawMenu();

  downButtonState = digitalRead(1);
  selectButtonState = digitalRead(0);
  upButtonState =   digitalRead(9);

  oneampState = digitalWrite(6);
  twoampState = digitalWrite(7);
  threeampState = digitalWrite(8);
 
  checkIfDownButtonIsPressed();
  checkIfUpButtonIsPressed();
  checkIfSelectButtonIsPressed();

 
 
  if (up == 1 )   //UP Button Menuitem Logics
  {
    up = false;
    menuitem--;
    if (menuitem==0)
    {
      menuitem=1;
    }
    if (menuitem==2)
    {
      menuitem=1;
    }
    if (menuitem==3)
    {
      menuitem=2;
    }
  }


  if (down == 1 ) //DOWN Button Menuitem Logics
  {
    down = false;
    menuitem++;
    if (menuitem==1)
    {
      menuitem=2;
    }
    if (menuitem==2)
    {
      menuitem=3;
    }
    if (menuitem==3)
    {
      menuitem=3;
    }
  }


    if (select == 1)
      {
        select = false;
        if(menuitem==1)
        {
          if(oneamp)
          {
        digitalWrite( oneampState, HIGH );
        digitalWrite( twoampState, LOW );
        digitalWrite( threeampState, LOW );
          }
      else
       {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );
       }
    }

     
      if (menuitem==2)
      {
        if(twoamp)
        {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, HIGH );
        digitalWrite( threeamp, LOW );
        }
      else
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );
       }
    }


   if (menuitem==3)
    {
      if (threeamp)
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, HIGH );
        }
      else
      {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );
       }
    }
     
    }     
  }

  void checkIfDownButtonIsPressed()
  {
    if (downButtonState != lastDownButtonState)
  {
    if (downButtonState == 1)
    {
      down=true;
    }
    delay(50);
  }
   lastDownButtonState = downButtonState;
  }

void checkIfUpButtonIsPressed()
{
  if (upButtonState != lastUpButtonState)
  {
    if (upButtonState == 1) {
      up=true;
    }
    delay(50);
  }
   lastUpButtonState = upButtonState;
}

void checkIfSelectButtonIsPressed()
{
   if (selectButtonState != lastSelectButtonState)
  {
    if (selectButtonState == 1) {
      select=true;
    }
    delay(50);
  }
   lastSelectButtonState = selectButtonState;
}

 
  void drawMenu()
  {
   
  if (page==1)
  {   
   
   
    lcd.setCursor(1, 0);
    lcd.print("MAIN MENU");
   
   
   
    if (menuitem==1)
  {
   
    lcd.setCursor(1, 1);
    lcd.print(">5V 1A: ");
     
    if (oneamp)
    {
      lcd.print(" ON ");
    }
    else
    {
      lcd.print(" OFF ");
    }
  }
 
 
    if (menuitem==2)
    {
     
      lcd.setCursor(1, 2);
      lcd.print(">5V 2A: ");

    if (twoamp)
    {
      lcd.print(" ON ");
    }
    else
    {
      lcd.print(" OFF ");
    }
   }
 
   
    if (menuitem==3)
    {
    lcd.setCursor(1, 3);
    lcd.print(">5V 3A: ");

    if (threeamp)
    {
      lcd.print(" ON ");
    }
    else
    {
      lcd.print(" OFF ");
    }
   }
  }
 }
 
 
 




 

Offline tsman

  • Frequent Contributor
  • **
  • Posts: 599
  • Country: gb
Re: How to stop flickering of LCD using Arduino Code?
« Reply #17 on: June 10, 2018, 08:43:16 pm »
You've got the pin variables all mixed up and weird in your latest version. oneamp/twoamp/threeamp used to be storing the pin number but you've changed it to be a boolean i.e. true/false variable instead now. Change it back to ints and set the pin numbers again.

Code: [Select]
boolean oneamp = false;
boolean twoamp = false;
boolean threeamp = false;

Your calls to digitalWrite are a mixture of oneamp and oneampState. Change it back. oneampState/twoampState/threeampState are all useless and can be removed along with the calls to digitalRead.

Code: [Select]
        digitalWrite( oneampState, HIGH );
        digitalWrite( twoampState, LOW );
        digitalWrite( threeampState, LOW );
          }
      else
       {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );

I've no idea what you're trying to do with this chunk of code with menuitem. If menuitem is 1 or 2 then it'll just set it to 3.

Code: [Select]
    if (menuitem==1)
    {
      menuitem=2;
    }
    if (menuitem==2)
    {
      menuitem=3;
    }
    if (menuitem==3)
    {
      menuitem=3;
    }
 
The following users thanked this post: radhika

Offline Cyberdragon

  • Super Contributor
  • ***
  • Posts: 2676
  • Country: us
Re: How to stop flickering of LCD using Arduino Code?
« Reply #18 on: June 11, 2018, 04:31:32 am »
The menu item code doesn't make sense. You are already using the incrementor (++) decrementor (--) which would do the same thing. Except you also have it trying to go to from zero to one in the decriment section, but since you decrimented before, it would be -1 before it reached and conditions and fail. Have it increment or decriment inside of the condition that checks the value

so if 0 add 1, if 2 subtract 1, exc. You could also eliminate the if 3 change to 3. Just use "else {}" and it will skip that (or any other) condition.

(I love how the server turned a piece of code into an emote) :o :palm: EDIT: it's not in a code block, that's why
*BZZZZZZAAAAAP*
Voltamort strikes again!
Explodingus - someone who frequently causes accidental explosions
 
The following users thanked this post: radhika

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: How to stop flickering of LCD using Arduino Code?
« Reply #19 on: June 11, 2018, 04:51:21 am »
what are you trying to achieve BTW?
Reading a sensor?
learning to make menus?
proper project?

Prettyprinting is a must for codes.
Simply put some delays in your code and vola,it'll be good enough
also,increase the clock speed to 16mhz if its 8mhz right now.(will require 5v as power source)
you've initialized   Serial with   Serial.begin(9600);  but I don't see you using serial anywhere throughout the code

I'd suggest,
you make a flow chart first,and then start typing code for it.

Here's a suggestion-
  • have all button inputs on single port
  • set a timer in background
  • the code starts,prints onto lcd whatever it's supposed to
  • wait for port with buttons to change
  • if change to port with button occurs,read sensors if any,redraw lcd,reset timer
  • if timer overflows,read sensors if any and redraw lcd


also try Atmel Studio,it's way better than arduino.
I only use arduino when I have to work with OLED (cause I haven't gotten time to read it's datasheet so far).


« Last Edit: June 11, 2018, 05:20:00 am by Raj »
 

Offline radhikaTopic starter

  • Regular Contributor
  • *
  • Posts: 105
  • Country: in
Re: How to stop flickering of LCD using Arduino Code?
« Reply #20 on: June 11, 2018, 08:54:32 am »
You've got the pin variables all mixed up and weird in your latest version. oneamp/twoamp/threeamp used to be storing the pin number but you've changed it to be a boolean i.e. true/false variable instead now. Change it back to ints and set the pin numbers again.

Code: [Select]
boolean oneamp = false;
boolean twoamp = false;
boolean threeamp = false;

Your calls to digitalWrite are a mixture of oneamp and oneampState. Change it back. oneampState/twoampState/threeampState are all useless and can be removed along with the calls to digitalRead.

Code: [Select]
        digitalWrite( oneampState, HIGH );
        digitalWrite( twoampState, LOW );
        digitalWrite( threeampState, LOW );
          }
      else
       {
        digitalWrite( oneamp, LOW );
        digitalWrite( twoamp, LOW );
        digitalWrite( threeamp, LOW );

I've no idea what you're trying to do with this chunk of code with menuitem. If menuitem is 1 or 2 then it'll just set it to 3.

Code: [Select]
    if (menuitem==1)
    {
      menuitem=2;
    }
    if (menuitem==2)
    {
      menuitem=3;
    }
    if (menuitem==3)
    {
      menuitem=3;
    }


This really work. I added oneamp in boolean, that is why my circuit is not working. But, after making it int back and removing oneampState, code work much better.
Thanks for your guidance.
#a5
Radhika Das
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: How to stop flickering of LCD using Arduino Code?
« Reply #21 on: June 11, 2018, 09:25:46 am »
You can certainly dynamically update a character LCD with no perceivable flicker, but you need your data ready to write at once, straight after clearing,
or better still, it’s a character LCD, and doesn’t need clearing. You can simply overwrite the display for each iteration of the main loop.

Either way there should only be a single instance in the program that writes to the LCD.
The other routines can write to an LCD data buffer, rather than writing to the LCD itself.


 
The following users thanked this post: radhika

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: How to stop flickering of LCD using Arduino Code?
« Reply #22 on: June 11, 2018, 10:02:26 am »
Coding with Arduino is done best if you make a flow chart first.
If you rewrite your program that way,I bet,it'll be smaller,faster,flawless
 
The following users thanked this post: radhika

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: How to stop flickering of LCD using Arduino Code?
« Reply #23 on: June 11, 2018, 11:26:45 am »
Code: [Select]
    if (menuitem==1)
    {
      menuitem=2;
    }
    if (menuitem==2)
    {
      menuitem=3;
    }
    if (menuitem==3)
    {
      menuitem=3;
    }
:o :palm:
Code: [Select]
menuitem += menuitem < 3;:-+
 
The following users thanked this post: radhika


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf