#include <LiquidCrystal.h>
class Symbol {
public:
// Properties
String name;
int nameSize;
int symbolId;
byte* characterBytes[8]; // Array of pointers to hold up to 8 byte arrays
int bytesCount; // Number of byte arrays for this symbol
// Positions for each character (x, y coordinates)
struct Position {
int x;
int y;
};
Position positions[8];
// Constructor for a symbol with multiple character byte arrays
Symbol(String symbolName, int id, byte* bytes[], int numBytes) {
name = symbolName;
nameSize = symbolName.length();
symbolId = id;
bytesCount = numBytes;
// Copy the byte array pointers
for (int i = 0; i < numBytes && i < 8; i++) {
characterBytes[i] = bytes[i];
}
}
// Method to set the position for each character
void setPosition(int index, int x, int y) {
if (index >= 0 && index < bytesCount) {
positions[index].x = x;
positions[index].y = y;
}
}
// Method to register the symbol with the LCD
void registerWithLCD(LiquidCrystal& lcd) {
for (int i = 0; i < bytesCount; i++) {
// Register each character at symbolId + i
lcd.createChar(symbolId + i, characterBytes[i]);
}
}
// Method to place the entire symbol on the LCD
void placeOnLCD(LiquidCrystal& lcd) {
// First register all characters
registerWithLCD(lcd);
// Then place each character at its position
for (int i = 0; i < bytesCount; i++) {
lcd.setCursor(positions[i].x, positions[i].y);
lcd.write(symbolId + i);
}
}
};
// Currency character byte arrays
byte currency0x6[] = { B00000, B00110, B01110, B01100, B01100, B01100, B11111, B01100 };
byte currency0x7[] = { B00000, B00011, B00111, B01100, B01100, B01100, B11111, B01100 };
byte currency0x8[] = { B00000, B10000, B11000, B01100, B01100, B01100, B11111, B01100 };
byte currency1x6[] = { B01100, B11111, B01100, B01100, B01100, B00111, B00011, B00000 };
byte currency1x7[] = { B01100, B11111, B01100, B01100, B01100, B11000, B10000, B00000 };
byte currency1x8[] = { B01100, B11111, B01100, B01100, B01100, B11100, B11000, B00000 };
void setup() {
// Initialize LCD
LiquidCrystal lcd(22, 23, 4, 5, 6, 7);
lcd.begin(16, 2);
// Create an array of byte pointers
byte* currencyBytes[] = {
currency0x6, currency0x7, currency0x8,
currency1x6, currency1x7, currency1x8
};
// Create a currency symbol object
Symbol currencySymbol("Currency", 1, currencyBytes, 6);
// Set positions for each character in the symbol (similar to your cherry example)
currencySymbol.setPosition(0, 6, 0); // currency0x6 at position (6,0)
currencySymbol.setPosition(1, 7, 0); // currency0x7 at position (7,0)
currencySymbol.setPosition(2, 8, 0); // currency0x8 at position (8,0)
currencySymbol.setPosition(3, 6, 1); // currency1x6 at position (6,1)
currencySymbol.setPosition(4, 7, 1); // currency1x7 at position (7,1)
currencySymbol.setPosition(5, 8, 1); // currency1x8 at position (8,1)
// Place the symbol on the LCD
currencySymbol.placeOnLCD(lcd);
}
void loop() {
// Your code here
}