Juri Pfammatter / AdafruitOLED128x64

OLEDTest.cpp

Committer:
pfammjur
Date:
2021-04-19
Revision:
17:b116da3bffbb
Child:
18:6ab8b740e55a

File content as of revision 17:b116da3bffbb:

/*
 *  Copyright (c) 2012 Neal Horman - http://www.wanlink.com
 *  
 *  License: MIT open source (http://opensource.org/licenses/MIT)
 *      Summary;
 *      Use / modify / distribute / publish it how you want and 
 *      if you use it, or don't, you can't hold me liable for how
 *      it does or doesn't work.
 *      If it doesn't work how you want, don't use it, or change
 *      it so that it does work.
 */
 
#include "mbed.h"
#include "Adafruit_SSD1306.h"
#include "platform/mbed_thread.h"                //Muss immer rein
#define SCREEN_ADRESS 0x3D
 
DigitalOut myled(LED1);
static BufferedSerial pc(USBTX, USBRX);         //pc Seriel für baud

using namespace std::chrono;                    //Namespce für printf



// an I2C sub-class that provides a constructed default
class I2CPreInit : public I2C
{
public:
    I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
    {
        frequency(400000);
        //start();
    };
};

 
I2CPreInit gI2C(I2C_SDA, I2C_SCL);         //I2CPreInit gI2C(d9,d10);
Adafruit_SSD1306_I2c gOled2(gI2C,D4,0x7A,64,128);    //Adafruit_SSD1306_I2c gOled2(gI2C,p27);
 
int main()
{   uint16_t i=0;
    //gOled2.begin(SSD1306_SWITCHCAPVCC);
    thread_sleep_for(1000);
    pc.set_baud(9600);                          //baudrate
    gOled2.clearDisplay();
    gOled2.drawPixel (10, 10,WHITE);
    gOled2.display();
    thread_sleep_for(1000);
    gOled2.clearDisplay();
    while(true)
    {
        gOled2.setTextCursor(0,0);
        gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height());
        gOled2.printf("Hello World\n");
        gOled2.printf("Laufnr.: %d\r",i);
        gOled2.display();
        i++;
        myled = !myled;
        thread_sleep_for(1000);
        gOled2.clearDisplay();
        //printf("%d",i);
    }
}