Hi, I am brand new to arduino and know virtuly nothing of programing other than what I picked up in the last few weeks....I recently was looking for a digital display to display the gear position of my camaro ('84) I previously made a button bank that lights up basic LED's on the shift patteren, but I thought it would be cool to have an accual display on the dash, I went to a local eletronics store and and they suggested an Arduino uno with a oled display ( https://www.amazon.com/gp/product/B0711 ... LMXA&psc=1 is what I ended up with), it was suggested to use Grok to help write the program which it did and it works exactally as I wanted it to with 1 issue; I cant change the font, the rest of the dashbord has 7/16 segment display and I was trying to get somthing to match (16 segment digital emulation 1/2"-5/8" tall), and all I can get is the basic font, or some other font that is not the right one and displays tiny. Following is the code that grok wrote for me:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1331.h>
// OLED SPI pins
#define SCLK_PIN 9 // SLC
#define SDA_PIN 10 // SDA/MOSI
#define RES_PIN 11 // Reset
#define DC_PIN 12 // Data/Command
#define CS_PIN 13 // Chip Select
// Color definitions
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
// Input pins for signals 1-7
const int signalPins[7] = {2, 3, 4, 5, 6, 7, 8}; // Digital pins 2-8
// Initialize OLED display
Adafruit_SSD1331 display = Adafruit_SSD1331(CS_PIN, DC_PIN, SDA_PIN, SCLK_PIN, RES_PIN);
// Variable to track the last displayed character
char lastChar = ' '; // Initialize with a non-display character
void setup() {
// Initialize signal pins as inputs with internal pull-down resistors
for (int i = 0; i < 7; i++) {
pinMode(signalPins[i], INPUT_PULLUP); // Use INPUT_PULLUP and invert logic
}
// Initialize display
display.begin();
display.fillScreen(BLACK);
// Set text properties
display.setTextSize(7); // Large text size
display.setTextWrap(false);
// Initial display
displayCharacter('N'); // Start with 'N'
lastChar = 'N';
}
void loop() {
char currentChar = getCurrentCharacter();
// Only update display if character has changed
if (currentChar != lastChar) {
displayCharacter(currentChar);
lastChar = currentChar;
}
delay(50); // Increased debounce delay
}
char getCurrentCharacter() {
// Check each signal pin (inverted logic due to INPUT_PULLUP)
for (int i = 0; i < 7; i++) {
if (digitalRead(signalPins[i]) == LOW) { // LOW means signal is present
if (i < 6) {
return '1' + i; // Returns '1' through '6'
} else {
return 'R'; // 7th pin returns 'R'
}
}
}
return 'N'; // No signal detected
}
void displayCharacter(char c) {
// Clear previous display
display.fillScreen(BLACK);
// Set color based on character
if (c == 'N') {
display.setTextColor(GREEN);
} else {
display.setTextColor(RED);
}
// Center the character (96x64 pixels display)
display.setCursor(32, 7); // Roughly centered
// Display the character
display.print(c);
}