#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "SdFat.h"
#define SPI_SPEED SD_SCK_MHZ(4)
#define CS_PIN A4
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
SdFat sd;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//Fix variable name casing, add '=', and end with ';'
const int BUTTON_PIN = A1;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Initialize the OLED display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
Serial.begin(115200);
if (!sd.begin(CS_PIN, SPI_SPEED)) {
if (sd.card()->errorCode()) {
Serial.println("SD initialization failed.");
} else if (sd.vol()->fatType() == 0) {
Serial.println("Can't find a valid FAT16/FAT32 partition.");
} else {
Serial.println("Can't determine error type");
}
return;
}
Serial.println("Files on card:");
Serial.println(" Size Name");
sd.ls(LS_R | LS_SIZE);
}
void loop() {
int buttonState = digitalRead(BUTTON_PIN);
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
if (buttonState == LOW) {
display.print("Vivaan is a gaymer!");
} else {
display.print("Waiting...");
}
display.display(); // Push the text buffer to the screen
delay(1000); // Small delay for stability
}
Loading
stm32-bluepill
stm32-bluepill
Loading
ssd1306
ssd1306