Getting one word only to blink

Good day to all,

Please assist in coding, I need the word "SMILIES" to blink on my display please.

Herewith the code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

int x = 0;
int input = A0;
int state = 0;

LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
lcd.init(); // initialize the lcd

// Print a message to the LCD.
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" ROUND COUNTER ");
lcd.setCursor(0, 1);
lcd.print(x);
lcd.print(" = SMILIES ");

}
void loop()
{
int counter = digitalRead(A0);
if (state == 0)
{
switch (counter) {

  case 1 : state = 1; lcd.setCursor (0, 1); x = x + 1; lcd.print(x); break;
  case 0 : state = 0; break;

}

}
}

Print the string "SMILIES", then sometime later print a string containing the same number of spaces as letters in "SMILIES".
Don't forget to position the cursor each time

Please remember to use code tags when posting code

Hi,

Appoligies re the code tags, I am new on the forum.

Thank you for the code, I did write it to the unit but SMILIES are not blinking, or am I not doing something correct?

You don't appear to be printing the spaces I suggested.

I do not want to be spoonfed as I really want to learn, ok I will try and print the spaces,

Thanks for your responses.

I would be grateful if you could post the entire code that I would need, my knowledge is limited at this early stage of this project.

Thank you very much

and

is somehow contradictory.

Post the last version of your sketch, in a new post, in code tags,
previously formatted with ctrl-T in the IDE.

Half an hour later...

So get your spoon ready and switch the brain off, if it was on. :upside_down_face:

#include <LiquidCrystal_I2C.h>

uint16_t x = 0;
const uint8_t input = A0;
bool smiliesVisible = true;
uint32_t lastSwap;
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  pinMode(input, INPUT_PULLUP);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print(F(" ROUND COUNTER "));
  lcd.setCursor(0, 1);
  lcd.print(x);
  lcd.print(F(" = SMILIES "));
}

void loop() {
  bool intputActive = digitalRead(input) == LOW;
  if (intputActive ) {
    lcd.setCursor (0, 1);
    lcd.print(++x);
  }
  if (millis() - lastSwap >= 250) {
    lastSwap = millis();
    lcd.setCursor(lenNum(x), 1);
    lcd.print(smiliesVisible ? F("          ") : F(" = SMILIES"));
    smiliesVisible = not smiliesVisible;
  }
}

uint8_t lenNum(uint16_t check) {
  if (check < 10) {
    return 1;
  }
  if (check < 100) {
    return 2;
  }
  if (check < 1000) {
    return 3;
  }
  if (check < 10000) {
    return 4;
  }
  return 5;
}

lol, I agree....

Thank you very much, it is really a big help.

AWESOME !!!!!!!!!

I probably used a different way to attach the button (closing to ground),
and I changed the x, which should have a more descriptive name, to an unsigned type.
An overflow to zero sounds more reasonable than overflowing into negative numbers.

That sketch basically just does what @TheMemberFormerlyKnownAsAWOL suggested.

It appears that the counter is simply adding numbers like crazy, without even activating the ir sensor

So you probably have to remove the pinMode, and swap the logic of the signal.

I hope it only counts when the signal is not activated.

I hope you meant to say "it counts up like crazy".
It would really speed up, if it was not slowed down by all the LCD printing.

Your initial design was "count while the signal is active", and you wanted to blink text,
so I assumed that the while was a design choice.

If you want to count single events, here a version that sports that
(again with a button closing to ground as an input signal)

#include <LiquidCrystal_I2C.h>
#include <Bounce2.h>
// https://github.com/thomasfredericks/Bounce2

uint16_t x = 0;
const uint8_t input = A0;
bool smiliesVisible = true;
uint32_t lastSwap;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Bounce button;

void setup() {
  button.attach(input, INPUT_PULLUP);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print(F(" ROUND COUNTER "));
  lcd.setCursor(0, 1);
  lcd.print(x);
  lcd.print(F(" = SMILIES "));
}

void loop() {
  if (button.update() && button.fell()) {
    lcd.setCursor (0, 1);
    lcd.print(++x);
  }
  if (millis() - lastSwap >= 250) {
    lastSwap = millis();
    lcd.setCursor(lenNum(x), 1);
    lcd.print(smiliesVisible ? F("          ") : F(" = SMILIES"));
    smiliesVisible = not smiliesVisible;
  }
}

uint8_t lenNum(uint16_t check) {
  if (check < 10) {
    return 1;
  }
  if (check < 100) {
    return 2;
  }
  if (check < 1000) {
    return 3;
  }
  if (check < 10000) {
    return 4;
  }
  return 5;
}
1 Like

This is exactly what I was after, I clearly did not convert my exact requirements in to text, thank you sir. I wish I had you on speed dial. lol

You would probably not like to spend that much money. :grinning:

Have a look at the Bounce2 library, it is lean and easy to grasp,
and you don't have to program the state change detection and debouncing by hand.

You should nevertheless program both actions at least once, to understand what is going on.

:laughing:

Understood, thanks again. :metal: