Working Version Of OLED
Dependencies: Adafruit_GFX mbed
main.cpp@0:a886e44467c7, 2016-04-21 (annotated)
- Committer:
- ipv1
- Date:
- Thu Apr 21 08:04:16 2016 +0000
- Revision:
- 0:a886e44467c7
Initial Working Commit for Atmel OLED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ipv1 | 0:a886e44467c7 | 1 | /* |
ipv1 | 0:a886e44467c7 | 2 | * Copyright (c) 2012 Neal Horman - http://www.wanlink.com |
ipv1 | 0:a886e44467c7 | 3 | * |
ipv1 | 0:a886e44467c7 | 4 | * License: MIT open source (http://opensource.org/licenses/MIT) |
ipv1 | 0:a886e44467c7 | 5 | * Summary; |
ipv1 | 0:a886e44467c7 | 6 | * Use / modify / distribute / publish it how you want and |
ipv1 | 0:a886e44467c7 | 7 | * if you use it, or don't, you can't hold me liable for how |
ipv1 | 0:a886e44467c7 | 8 | * it does or doesn't work. |
ipv1 | 0:a886e44467c7 | 9 | * If it doesn't work how you want, don't use it, or change |
ipv1 | 0:a886e44467c7 | 10 | * it so that it does work. |
ipv1 | 0:a886e44467c7 | 11 | */ |
ipv1 | 0:a886e44467c7 | 12 | |
ipv1 | 0:a886e44467c7 | 13 | #include "mbed.h" |
ipv1 | 0:a886e44467c7 | 14 | #include "Adafruit_SSD1306.h" |
ipv1 | 0:a886e44467c7 | 15 | |
ipv1 | 0:a886e44467c7 | 16 | DigitalOut myled(LED1); |
ipv1 | 0:a886e44467c7 | 17 | |
ipv1 | 0:a886e44467c7 | 18 | // an SPI sub-class that provides a constructed default |
ipv1 | 0:a886e44467c7 | 19 | class SPIPreInit : public SPI |
ipv1 | 0:a886e44467c7 | 20 | { |
ipv1 | 0:a886e44467c7 | 21 | public: |
ipv1 | 0:a886e44467c7 | 22 | SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) |
ipv1 | 0:a886e44467c7 | 23 | { |
ipv1 | 0:a886e44467c7 | 24 | format(8,3); |
ipv1 | 0:a886e44467c7 | 25 | frequency(2000000); |
ipv1 | 0:a886e44467c7 | 26 | }; |
ipv1 | 0:a886e44467c7 | 27 | }; |
ipv1 | 0:a886e44467c7 | 28 | |
ipv1 | 0:a886e44467c7 | 29 | // an I2C sub-class that provides a constructed default |
ipv1 | 0:a886e44467c7 | 30 | class I2CPreInit : public I2C |
ipv1 | 0:a886e44467c7 | 31 | { |
ipv1 | 0:a886e44467c7 | 32 | public: |
ipv1 | 0:a886e44467c7 | 33 | I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) |
ipv1 | 0:a886e44467c7 | 34 | { |
ipv1 | 0:a886e44467c7 | 35 | frequency(400000); |
ipv1 | 0:a886e44467c7 | 36 | start(); |
ipv1 | 0:a886e44467c7 | 37 | }; |
ipv1 | 0:a886e44467c7 | 38 | }; |
ipv1 | 0:a886e44467c7 | 39 | |
ipv1 | 0:a886e44467c7 | 40 | SPIPreInit gSpi(PA_8,PA_7,PA_6); |
ipv1 | 0:a886e44467c7 | 41 | Adafruit_SSD1306_Spi gOled1(gSpi,PC_6,PA_0,PA_5); |
ipv1 | 0:a886e44467c7 | 42 | |
ipv1 | 0:a886e44467c7 | 43 | |
ipv1 | 0:a886e44467c7 | 44 | int main() |
ipv1 | 0:a886e44467c7 | 45 | { uint16_t x=0; |
ipv1 | 0:a886e44467c7 | 46 | |
ipv1 | 0:a886e44467c7 | 47 | gOled1.printf("%ux%u OLED Display\r\n", gOled1.width(), gOled1.height()); |
ipv1 | 0:a886e44467c7 | 48 | |
ipv1 | 0:a886e44467c7 | 49 | while(1) |
ipv1 | 0:a886e44467c7 | 50 | { |
ipv1 | 0:a886e44467c7 | 51 | myled = !myled; |
ipv1 | 0:a886e44467c7 | 52 | gOled1.printf("%u\r",x); |
ipv1 | 0:a886e44467c7 | 53 | gOled1.display(); |
ipv1 | 0:a886e44467c7 | 54 | x++; |
ipv1 | 0:a886e44467c7 | 55 | wait(1.0); |
ipv1 | 0:a886e44467c7 | 56 | } |
ipv1 | 0:a886e44467c7 | 57 | } |