Skip to main content
deleted 51 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

Blinkin Blinking cursor on arduinoArduino is inconsistent and misses inputs

I am trying to write a part of a program that prints time and allows the user to move a cursor across it. I have the following codecode, but there are a few issues with it.

#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <Time.h>
#include <TimeLib.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  lcd.begin(16,2);
  setTime(12,30,15,0,0,0);
 
}
 
int col = 0; 

void loop() {
  uint8_t buttons = lcd.readButtons(); //create readable buttons
  char time_out[16];
  lcd.setCursor(0,0);
  sprintf(time_out, "%02u:%02u:%02u",hour(),minute(),second());
  lcd.print(time_out);
  
  lcd.setCursor(col,0);
  lcd.blink();
  delay(100);
  
  if (buttons) {
    lcd.clear();
    if (buttons & BUTTON_RIGHT) { 
      col += 1;
    }   
    if (buttons & BUTTON_LEFT) {
      col -= 1; 
    } 
  } //buttons 
}

If you upload this to your board, you can tell that the blinking is highly irregular, not at all aesthetically pleasing.

You'll also notice that sometimes, when pressing left/right, the input isn't registered.

I suspect this has to do something with the delay() function used, which pauses the entire program.

I looked into the following method https://www.arduino.cc/en/Tutorial/BlinkWithoutDelaythe following method, but this does not work when needing to print something in a loop (as the time library requires).

Any idea how I could make this work better (regular blinking times and no miss of user input)?

Thanks a lot!

Blinkin cursor on arduino is inconsistent and misses inputs

I am trying to write a part of a program that prints time and allows the user to move a cursor across it. I have the following code, but there are a few issues with it.

#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <Time.h>
#include <TimeLib.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  lcd.begin(16,2);
  setTime(12,30,15,0,0,0);
 
}
 
int col = 0;
void loop() {
  uint8_t buttons = lcd.readButtons(); //create readable buttons
  char time_out[16];
  lcd.setCursor(0,0);
  sprintf(time_out, "%02u:%02u:%02u",hour(),minute(),second());
  lcd.print(time_out);
  
  lcd.setCursor(col,0);
  lcd.blink();
  delay(100);
  
  if (buttons) {
    lcd.clear();
    if (buttons & BUTTON_RIGHT) { 
      col += 1;
    }   
    if (buttons & BUTTON_LEFT) {
      col -= 1; 
    } 
  } //buttons 
}

If you upload this to your board, you can tell that the blinking is highly irregular, not at all aesthetically pleasing.

You'll also notice that sometimes, when pressing left/right, the input isn't registered.

I suspect this has to do something with the delay() function used, which pauses the entire program.

I looked into the following method https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay, but this does not work when needing to print something in a loop (as the time library requires)

Any idea how I could make this work better (regular blinking times and no miss of user input)?

Thanks a lot!

Blinking cursor on Arduino is inconsistent and misses inputs

I am trying to write a part of a program that prints time and allows the user to move a cursor across it. I have the following code, but there are a few issues with it.

#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <Time.h>
#include <TimeLib.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  lcd.begin(16,2);
  setTime(12,30,15,0,0,0);
}
int col = 0; 

void loop() {
  uint8_t buttons = lcd.readButtons(); //create readable buttons
  char time_out[16];
  lcd.setCursor(0,0);
  sprintf(time_out, "%02u:%02u:%02u",hour(),minute(),second());
  lcd.print(time_out);
  lcd.setCursor(col,0);
  lcd.blink();
  delay(100);
  if (buttons) {
    lcd.clear();
    if (buttons & BUTTON_RIGHT) { 
      col += 1;
    }   
    if (buttons & BUTTON_LEFT) {
      col -= 1; 
    } 
  } //buttons 
}

If you upload this to your board, you can tell that the blinking is highly irregular, not at all aesthetically pleasing.

You'll also notice that sometimes, when pressing left/right, the input isn't registered.

I suspect this has to do something with the delay() function used, which pauses the entire program.

I looked into the following method, but this does not work when needing to print something in a loop (as the time library requires).

Any idea how I could make this work better (regular blinking times and no miss of user input)?

Thanks a lot!

Source Link
Jon Goe
  • 89
  • 3
  • 8

Blinkin cursor on arduino is inconsistent and misses inputs

I am trying to write a part of a program that prints time and allows the user to move a cursor across it. I have the following code, but there are a few issues with it.

#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <Time.h>
#include <TimeLib.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  lcd.begin(16,2);
  setTime(12,30,15,0,0,0);

}

int col = 0;
void loop() {
  uint8_t buttons = lcd.readButtons(); //create readable buttons
  char time_out[16];
  lcd.setCursor(0,0);
  sprintf(time_out, "%02u:%02u:%02u",hour(),minute(),second());
  lcd.print(time_out);
  
  lcd.setCursor(col,0);
  lcd.blink();
  delay(100);
  
  if (buttons) {
    lcd.clear();
    if (buttons & BUTTON_RIGHT) { 
      col += 1;
    }   
    if (buttons & BUTTON_LEFT) {
      col -= 1; 
    } 
  } //buttons 
}

If you upload this to your board, you can tell that the blinking is highly irregular, not at all aesthetically pleasing.

You'll also notice that sometimes, when pressing left/right, the input isn't registered.

I suspect this has to do something with the delay() function used, which pauses the entire program.

I looked into the following method https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay, but this does not work when needing to print something in a loop (as the time library requires)

Any idea how I could make this work better (regular blinking times and no miss of user input)?

Thanks a lot!