Skip to content

Instantly share code, notes, and snippets.

@smcl
Last active December 17, 2015 11:28
Show Gist options
  • Save smcl/684ee96fa6e5afa1d382 to your computer and use it in GitHub Desktop.
Save smcl/684ee96fa6e5afa1d382 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
int frames;
unsigned long startTime;
unsigned long endTime;
void setup() {
// initialise the SSD1306
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC);
// setup font
display.setTextSize(4);
display.setTextColor(WHITE);
// display
frames = 0;
startTime = millis();
}
void loop() {
// dump the frame rate every 100 frames
if (frames == 100) {
endTime = millis();
float seconds = (endTime - startTime) / 1000.0;
float fps = ((float)frames) / seconds;
display.clearDisplay();
display.setCursor(0, 0);
char str[8]; // probably too big
sprintf(str, "%u fps", round(fps));
display.print(str);
startTime = millis();
frames = 0;
}
display.display();
frames++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment