Test with EzSbc2 LPC1347 board and Adafruit 0,96" display, connected to i2c
Dependencies: Adafruit_GFX I2CDevLib MPU9150 SmallGUI USBDevice WeeESP8266 mbed nRF24L01P
main.cpp@0:e1e154fcc87e, 2014-11-17 (annotated)
- Committer:
- JojoS
- Date:
- Mon Nov 17 22:48:00 2014 +0000
- Revision:
- 0:e1e154fcc87e
- Child:
- 2:2eb3f38f9141
Test program for Adafruit SS1306 display, running on a LPC1347 target
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JojoS | 0:e1e154fcc87e | 1 | #include "mbed.h" |
JojoS | 0:e1e154fcc87e | 2 | #include "Adafruit_SSD1306.h" |
JojoS | 0:e1e154fcc87e | 3 | |
JojoS | 0:e1e154fcc87e | 4 | |
JojoS | 0:e1e154fcc87e | 5 | // modified für EzSBC2 |
JojoS | 0:e1e154fcc87e | 6 | |
JojoS | 0:e1e154fcc87e | 7 | DigitalOut ledRed(P1_16); |
JojoS | 0:e1e154fcc87e | 8 | DigitalOut ledGreen(P1_15); |
JojoS | 0:e1e154fcc87e | 9 | |
JojoS | 0:e1e154fcc87e | 10 | // an SPI sub-class that provides a constructed default |
JojoS | 0:e1e154fcc87e | 11 | class SPI2 : public SPI |
JojoS | 0:e1e154fcc87e | 12 | { |
JojoS | 0:e1e154fcc87e | 13 | public: |
JojoS | 0:e1e154fcc87e | 14 | SPI2(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) |
JojoS | 0:e1e154fcc87e | 15 | { |
JojoS | 0:e1e154fcc87e | 16 | format(8,3); |
JojoS | 0:e1e154fcc87e | 17 | frequency(2000000); |
JojoS | 0:e1e154fcc87e | 18 | }; |
JojoS | 0:e1e154fcc87e | 19 | }; |
JojoS | 0:e1e154fcc87e | 20 | |
JojoS | 0:e1e154fcc87e | 21 | // an I2C sub-class that provides a constructed default |
JojoS | 0:e1e154fcc87e | 22 | class I2C2 : public I2C |
JojoS | 0:e1e154fcc87e | 23 | { |
JojoS | 0:e1e154fcc87e | 24 | public: |
JojoS | 0:e1e154fcc87e | 25 | I2C2(PinName sda, PinName scl) : I2C(sda, scl) |
JojoS | 0:e1e154fcc87e | 26 | { |
JojoS | 0:e1e154fcc87e | 27 | frequency(400000); |
JojoS | 0:e1e154fcc87e | 28 | start(); |
JojoS | 0:e1e154fcc87e | 29 | }; |
JojoS | 0:e1e154fcc87e | 30 | }; |
JojoS | 0:e1e154fcc87e | 31 | |
JojoS | 0:e1e154fcc87e | 32 | |
JojoS | 0:e1e154fcc87e | 33 | I2C2 gI2C(P0_5, P0_4); |
JojoS | 0:e1e154fcc87e | 34 | Adafruit_SSD1306_I2c gOled2(gI2C, P0_21, 0x78, 64, 128); |
JojoS | 0:e1e154fcc87e | 35 | // Adafruit_SSD1306_I2c gOled2(gI2C, NC, 0x78, 64, 128); // works only with mbed libs < version 86 |
JojoS | 0:e1e154fcc87e | 36 | |
JojoS | 0:e1e154fcc87e | 37 | int main() |
JojoS | 0:e1e154fcc87e | 38 | { |
JojoS | 0:e1e154fcc87e | 39 | uint16_t x=0; |
JojoS | 0:e1e154fcc87e | 40 | |
JojoS | 0:e1e154fcc87e | 41 | //while(1) |
JojoS | 0:e1e154fcc87e | 42 | { |
JojoS | 0:e1e154fcc87e | 43 | ledRed = 1; |
JojoS | 0:e1e154fcc87e | 44 | ledGreen = 0; |
JojoS | 0:e1e154fcc87e | 45 | wait(0.5); |
JojoS | 0:e1e154fcc87e | 46 | |
JojoS | 0:e1e154fcc87e | 47 | ledRed = 0; |
JojoS | 0:e1e154fcc87e | 48 | ledGreen = 1; |
JojoS | 0:e1e154fcc87e | 49 | wait(0.5); |
JojoS | 0:e1e154fcc87e | 50 | } |
JojoS | 0:e1e154fcc87e | 51 | |
JojoS | 0:e1e154fcc87e | 52 | gOled2.clearDisplay(); |
JojoS | 0:e1e154fcc87e | 53 | gOled2.display(); |
JojoS | 0:e1e154fcc87e | 54 | |
JojoS | 0:e1e154fcc87e | 55 | //gOled2.setTextCursor(1, 0); |
JojoS | 0:e1e154fcc87e | 56 | gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height()); |
JojoS | 0:e1e154fcc87e | 57 | |
JojoS | 0:e1e154fcc87e | 58 | while(1) |
JojoS | 0:e1e154fcc87e | 59 | { |
JojoS | 0:e1e154fcc87e | 60 | ledRed = !ledRed; |
JojoS | 0:e1e154fcc87e | 61 | |
JojoS | 0:e1e154fcc87e | 62 | gOled2.setTextCursor(0, 10); |
JojoS | 0:e1e154fcc87e | 63 | gOled2.printf("%u\r", x); |
JojoS | 0:e1e154fcc87e | 64 | gOled2.display(); |
JojoS | 0:e1e154fcc87e | 65 | |
JojoS | 0:e1e154fcc87e | 66 | x++; |
JojoS | 0:e1e154fcc87e | 67 | wait(1.0); |
JojoS | 0:e1e154fcc87e | 68 | } |
JojoS | 0:e1e154fcc87e | 69 | // AnalogOut sine(PA_4); |
JojoS | 0:e1e154fcc87e | 70 | |
JojoS | 0:e1e154fcc87e | 71 | |
JojoS | 0:e1e154fcc87e | 72 | } |