Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 52 additions & 28 deletions examples/simple_demo_avr/simple_demo_avr.ino
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
#include <Arduino.h>
//
// OneBitDisplay library demo for AVR platform,
// without line drawing function (saving of 1K RAM)
//

#include <OneBitDisplay.h>


// I²C Setup
#define SDA_PIN A4 // change if needed according to your setup
#define SCL_PIN A5 // change if needed according to your setup ()
#define USE_HW_I2C 1 // Use bit banging to get higher speed output
#define OLED_ADDR -1 // let OneBitDisplay find the address of our display

// Screen Setup
#define OLED_SIZE OLED_72x40 // Size of the display
#define RESET_PIN -1 // Using the mcu reset
#define FLIP180 0
#define INVERT 0
#define WIDTH 72 // Helper to calculate te buffer size according to the screen width in pixels
#define HEIGHT 40 // Helper to calculate te buffer size according to the screen height in pixels
#define BUFFER_SIZE (WIDTH*HEIGHT) / 8 // the actual size of the buffer needed for your screen

// Globals
OBDISP obd;
#define SDA_PIN -1
#define SCL_PIN -1
// no reset pin needed
#define RESET_PIN -1
// let OneBitDisplay find the address of our display
#define OLED_ADDR -1
#define FLIP180 0
#define INVERT 0
// Use the default Wire library
#define USE_HW_I2C 1
static uint8_t ucBuffer[BUFFER_SIZE] = {0};

void setup()
{

int rc;
rc = obdI2CInit(&obd, OLED_128x64, OLED_ADDR, FLIP180, INVERT, USE_HW_I2C, SDA_PIN, SCL_PIN, RESET_PIN, 400000L); // Standard HW I2C bus at 400Khz

rc = obdI2CInit(&obd, OLED_SIZE, OLED_ADDR, FLIP180, INVERT, USE_HW_I2C, SDA_PIN, SCL_PIN, RESET_PIN, 400000L); // Standard HW I2C bus at 400Khz
if (rc != OLED_NOT_FOUND)
{
obdSetBackBuffer(&obd, ucBuffer);

char *msgs[] =
{
(char *)"SSD1306 @ 0x3C",
Expand All @@ -30,32 +43,43 @@ void setup()
(char *)"SH1106 @ 0x3D"
};

obdFill(&obd, 0, 1);
obdWriteString(&obd, 0, 0, 0, (char *)"OLED found:", FONT_8x8, 0, 1);
obdWriteString(&obd, 0, 10, 2, msgs[rc], FONT_8x8, 0, 1);
// Display address and chipset
obdFill(&obd, 0x00, 1);
obdSetTextWrap(&obd, 1 );
obdWriteString(&obd, 0, 0, 0, (char *)"OLED found:", FONT_SMALL, OBD_BLACK, 1);
obdWriteString(&obd, 0, 0, 8, msgs[rc], FONT_SMALL, OBD_BLACK, 1);
delay(3000);

// Display a rectangle for demo
obdFill(&obd, 0x00, 1);
obdRectangle(&obd, 0, 0, obd.width-1, obd.height-1, OBD_BLACK, 0);
obdDumpBuffer(&obd, ucBuffer);
delay(3000);
}
}

void loop()
{
int i, x, y;

obdFill(&obd, 0, 1);
obdWriteString(&obd, 0, 28, 0,(char *)"OLED Demo", FONT_8x8, 0, 1);
obdWriteString(&obd, 0, 0, 1,(char *)"Written by Larry Bank", FONT_6x8, 1, 1);
obdWriteString(&obd, 0, 0, 3,(char *)"**Demo**", FONT_16x16, 0, 1);
obdWriteString(&obd, 0, 9, 6,(char *)"for AVR", FONT_16x16, 0, 1);

obdFill(&obd, 0x00, 1);
obdWriteString(&obd, 0, 0, 0,(char *)"OLED Demo", FONT_NORMAL, OBD_BLACK, 1);
obdSetTextWrap(&obd, 1 );
obdWriteString(&obd, 0, 0, -1,(char *)"Written by Larry Bank", FONT_SMALL, OBD_BLACK, 1);
obdWriteString(&obd, 0, 0, -1,(char *)"**Demo**", FONT_NORMAL, OBD_BLACK, 1);
obdWriteString(&obd, 0, 9, -1,(char *)"for AVR", FONT_NORMAL, OBD_BLACK, 1);

delay(2000);
obdFill(&obd, 0, 1);

obdFill(&obd, 0x00, 1);

for (i = 0; i < 1000; i++)
for (i = 0; i < 30; i++)
{
x = random(128);
y = random(64);
obdSetPixel(&obd, x, y, 1, 1);
x = random(obd.width);
y = random(obd.height);
obdSetPixel(&obd, x, y, OBD_BLACK, 1);
obdDumpBuffer(&obd, ucBuffer);
}

delay(2000);
}
}