Hello everyone!
Im almost done with my project.. i just need to add a screensaver flashing text to my I2C LCD whenever the system is idle for 25 seconds.. the problem is i have this weird flickering on the LCD whenever the text change..
I know it has something to do with changing the text so fast that the LCD cannot keep up with the refresh rate. Below is part of the screensaver code..
By the way i did not make this code.. some guy share this code from other forum site and i just modify it.. credit to him!
Is there any fix to this?
if (button == HIGH) {
screensaver++;
delay(5);
if (screensaver > 24000){
screensaver = 25005;
o++;
if (o>500){
o1++;
o=0;
if (o1 >= 5){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 1"));
lcd.setCursor(0, 1);
lcd.print(F("Select 1"));
o=0;}
if(o1 >= 10){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 2"));
lcd.setCursor(0, 1);
lcd.print(F("Select 2"));
o=0;}
if(o1 >= 15){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 3"));
lcd.setCursor(0, 1);
lcd.print(F("Select 3"));
o=0;}
if(o1 >= 20){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 4"));
lcd.setCursor(0, 1);
lcd.print(F("Select 4"));
o=0;}
if(o1 >= 25){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 5"));
lcd.setCursor(0, 1);
lcd.print(F("Select 5"));
o=0;}
if(o1 >= 30){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Enjoy"));
lcd.setCursor(0, 1);
lcd.print(F("Thankyou!"));
o=0;}
if(o1 >= 35){
o1=0;
}}}}}
Consider asking the guy who wrote the code for help.
jremington:
Consider asking the guy who wrote the code for help.
i did. and its been months he never gets back online..
Putting aside opinions about how the "screen saver" is done:
In your code you have these compares:
if (o1 >= 5)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 1"));
lcd.setCursor(0, 1);
lcd.print(F("Select 1"));
o = 0;
}
if (o1 >= 10)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 2"));
lcd.setCursor(0, 1);
lcd.print(F("Select 2"));
o = 0;
}
if (o1 >= 15)
{
Think about what happens when o1 is, say, 15: All of these compares will be true and will execute, giving noisy crappy results on screen. You need to rethink the logic and add some "else" statements. Maybe something like:
.
.
.
if( o1 >= 35 )
{
o1 = 0;
}//if
else if( o1 >= 30 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Enjoy"));
lcd.setCursor(0, 1);
lcd.print(F("Thankyou!"));
o = 0;
}//else
else if( o1 >= 25 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 5"));
lcd.setCursor(0, 1);
lcd.print(F("Select 5"));
o = 0;
}//elseif
else if( o1 >= 20 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 4"));
lcd.setCursor(0, 1);
lcd.print(F("Select 4"));
o = 0;
}//elseif
else if( o1 >=15 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 3"));
lcd.setCursor(0, 1);
lcd.print(F("Select 3"));
o = 0;
}//elseif
else if( o1 >= 10 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 2"));
lcd.setCursor(0, 1);
lcd.print(F("Select 2"));
o = 0;
}//elseif
else if( o1 >=5 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 1"));
lcd.setCursor(0, 1);
lcd.print(F("Select 1"));
o = 0;
}//elseif
.
.
.
If you waited months for an answer, it does not seem to be a pressing issue.
Think about what happens when o1 is, say, 15: All of these compares will be true and will execute, giving noisy crappy results on screen. You need to rethink the logic and add some "else" statements. Maybe something like:
.
.
.
if( o1 >= 35 )
{
o1 = 0;
}//if
else if( o1 >= 30 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Enjoy"));
lcd.setCursor(0, 1);
lcd.print(F("Thankyou!"));
o = 0;
}//else
else if( o1 >= 25 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 5"));
lcd.setCursor(0, 1);
lcd.print(F("Select 5"));
o = 0;
}//elseif
else if( o1 >= 20 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 4"));
lcd.setCursor(0, 1);
lcd.print(F("Select 4"));
o = 0;
}//elseif
else if( o1 >=15 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 3"));
lcd.setCursor(0, 1);
lcd.print(F("Select 3"));
o = 0;
}//elseif
else if( o1 >= 10 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 2"));
lcd.setCursor(0, 1);
lcd.print(F("Select 2"));
o = 0;
}//elseif
else if( o1 >=5 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 1"));
lcd.setCursor(0, 1);
lcd.print(F("Select 1"));
o = 0;
}//elseif
.
.
.
Will this code exit anytime a button is pressed? this is a screensaver.. i want to exit the screensaver anytime a button is press.
[/quote]
I don't know. Here it is in the code snippet you gave. Try it.
if (button == HIGH)
{
screensaver++;
delay(5);
if (screensaver > 24000)
{
screensaver = 25005;
o++;
//lcd.setCursor(0, 3);
//lcd.print(o);
if (o > 500)
{
o1++;
o = 0;
if( o1 >= 35 )
{
o1 = 0;
}//if
else if( o1 >= 30 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Enjoy"));
lcd.setCursor(0, 1);
lcd.print(F("Thankyou!"));
o = 0;
}//else
else if( o1 >= 25 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 5"));
lcd.setCursor(0, 1);
lcd.print(F("Select 5"));
o = 0;
}//elseif
else if( o1 >= 20 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 4"));
lcd.setCursor(0, 1);
lcd.print(F("Select 4"));
o = 0;
}//elseif
else if( o1 >=15 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 3"));
lcd.setCursor(0, 1);
lcd.print(F("Select 3"));
o = 0;
}//elseif
else if( o1 >= 10 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 2"));
lcd.setCursor(0, 1);
lcd.print(F("Select 2"));
o = 0;
}//elseif
else if( o1 >=5 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 1"));
lcd.setCursor(0, 1);
lcd.print(F("Select 1"));
o = 0;
}//elseif
}//if
}//if
}//if
Blackfin:
I don't know. Here it is in the code snippet you gave. Try it.
if (button == HIGH)
{
screensaver++;
delay(5);
if (screensaver > 24000)
{
screensaver = 25005;
o++;
//lcd.setCursor(0, 3);
//lcd.print(o);
if (o > 500)
{
o1++;
o = 0;
if( o1 >= 35 )
{
o1 = 0;
}//if
else if( o1 >= 30 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Enjoy"));
lcd.setCursor(0, 1);
lcd.print(F("Thankyou!"));
o = 0;
}//else
else if( o1 >= 25 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 5"));
lcd.setCursor(0, 1);
lcd.print(F("Select 5"));
o = 0;
}//elseif
else if( o1 >= 20 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 4"));
lcd.setCursor(0, 1);
lcd.print(F("Select 4"));
o = 0;
}//elseif
else if( o1 >=15 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 3"));
lcd.setCursor(0, 1);
lcd.print(F("Select 3"));
o = 0;
}//elseif
else if( o1 >= 10 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 2"));
lcd.setCursor(0, 1);
lcd.print(F("Select 2"));
o = 0;
}//elseif
else if( o1 >=5 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Display Ad 1"));
lcd.setCursor(0, 1);
lcd.print(F("Select 1"));
o = 0;
}//elseif
}//if
}//if
}//if
ok let me try it! one more question.. will this loop over and over again until a button is press?
projectdimpreza:
ok let me try it! one more question.. will this loop over and over again until a button is press?
I don't know. You've only posted a bit of your code. I don't know what precedes "if button == high"; assuming button is HIGH each pass this code should execute.
Blackfin:
I don't know. You've only posted a bit of your code. I don't know what precedes "if button == high"; assuming button is HIGH each pass this code should execute.
if the button is HIGH for 25 seconds screensaver will be displayed.. but when button is LOW which is button is press and the button circuit is cut.. it will display something else on sa LCD..
Right now i think the screen saver is working fine! it exits whenever a button is pressed and it loops forever aslong as the system is idle..
ill let u know if theres a bug.. ill test this system for a now..
Thanks Blackfin !