Skip to content

ok i have it compiling now but its displaying some very strange characters on screen just like random blocks? any idea about this #3

@DirtyDerv

Description

@DirtyDerv

ok i have it compiling now but its displaying some very strange characters on screen just like random blocks? any idea about this

`#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>

//#define USE_PARALLEL_2004_LCD // Is default
//#define USE_PARALLEL_1602_LCD
#define USE_SERIAL_2004_LCD
//#define USE_SERIAL_1602_LCD
#include "LCDBigNumbers.hpp" // Include sources for LCD big number generation

#if defined(USE_PARALLEL_LCD)
LiquidCrystal myLCD(2, 3, 4, 5, 6, 7); // Depends on your actual connections
//LiquidCrystal myLCD(4, 5, 6, 7, 8, 9); // Sample connections starting at pin 4
#else
#define LCD_I2C_ADDRESS 0x27 // Default LCD address is 0x27 for a 20 chars and 4 line / 2004 display
LiquidCrystal_I2C LCD(LCD_I2C_ADDRESS, LCD_COLUMNS, LCD_ROWS); // LCD_COLUMNS and LCD_ROWS are set by LCDBigNumbers.hpp depending on the defined display
#endif

/*

  • Available big number fonts are: BIG_NUMBERS_FONT_1_COLUMN_2_ROWS_VARIANT_1, BIG_NUMBERS_FONT_2_COLUMN_2_ROWS_VARIANT_1,
  • BIG_NUMBERS_FONT_3_COLUMN_2_ROWS_VARIANT_1, BIG_NUMBERS_FONT_3_COLUMN_2_ROWS_VARIANT_2, BIG_NUMBERS_FONT_3_COLUMN_2_ROWS_VARIANT_3,
  • BIG_NUMBERS_FONT_2_COLUMN_3_ROWS_VARIANT_1, BIG_NUMBERS_FONT_2_COLUMN_3_ROWS_VARIANT_2, ,
  • BIG_NUMBERS_FONT_3_COLUMN_4_ROWS_VARIANT_1, BIG_NUMBERS_FONT_3_COLUMN_4_ROWS_VARIANT_2
    */
    LCDBigNumbers myLCD(&LCD, BIG_NUMBERS_FONT_3_COLUMN_3_ROWS_VARIANT_1); // Use 3x3 numbers

const int encoderPinA = 2;
const int encoderPinB = 3;

volatile int encoderValue = 0;

float encoderPPM = 1000.0;
float screwPitch = 0.5;

const int eepromAddress = 0;
int lastSavedValue = 0;

void setup() {
LCD.init();
LCD.clear();
LCD.backlight();
Serial.begin(115200);
pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);

attachInterrupt(digitalPinToInterrupt(encoderPinA), updateEncoder, CHANGE);
//myLCD.begin();
// Load the last saved encoder value from EEPROM
encoderValue = EEPROM.read(eepromAddress);
}

void loop() {
//float position = (encoderValue / encoderPPM) * screwPitch;
float position = 9876.54;
//displayFormattedNumber(position);
myLCD.print((int)position);
//Serial.println(position);
// Display the formatted number using LCDmyLCD
//myLCD.setBigNumberCursor(0);
//myLCD.print(position); // Correct usage of displayNumber

if (encoderValue != lastSavedValue) {
lastSavedValue = encoderValue;
EEPROM.write(eepromAddress, encoderValue);
}

delay(100);
}

void updateEncoder() {
int stateA = digitalRead(encoderPinA);
int stateB = digitalRead(encoderPinB);

if (stateA == stateB) {
encoderValue++;
} else {
encoderValue--;
}
}

void displayFormattedNumber(float number) {
int integerPart = (int)number;
int decimalPart = (int)((number - integerPart) * 10);
myLCD.print(integerPart);

//Serial.println((int)number);
//myLCD.setBigNumberCursor(0);
//myLCD.print((integerPart / 1000));
//Serial.println((integerPart / 1000));
//myLCD.setBigNumberCursor(5);
//Serial.println("thous");
//myLCD.print((integerPart / 100) % 10);
//Serial.println((integerPart / 100) % 10);
//myLCD.setBigNumberCursor(9);
//myLCD.print((integerPart / 10) % 10);
//Serial.println((integerPart / 10) % 10);
//myLCD.setBigNumberCursor(13);
//myLCD.print(integerPart % 10);
//Serial.println(integerPart % 10);

//printColon(13, 1);
//myLCD.setBigNumberCursor(17);
//myLCD.print(decimalPart);
}

void printColon(byte leftAdjust, byte topAdjust) {
for (byte row = 0; row < (4 - topAdjust); row++) {
myLCD.setBigNumberCursor(15, 4);
if (topAdjust == 1) {
if (row == 0 || row == 1) myLCD.print(F(" "));
else myLCD.print(F(" "));
} else {
if (row == 1 || row == 2) myLCD.print(F("."));
else myLCD.print(F(" "));
}
}
}`

Originally posted by @DirtyDerv in #2 (reply in thread)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions