![](/media/cache/profiles/17a98ed636b0294602e63e75d11339a2.jpg.50x50_q85.jpg)
read TI TMP102 temperature and display on SSD1306 OLED
Dependencies: Adafruit_GFX TMP102 mbed
Fork of DisplayOled by
main.cpp@0:3b87797f65fc, 2017-05-16 (annotated)
- Committer:
- franni
- Date:
- Tue May 16 15:18:54 2017 +0000
- Revision:
- 0:3b87797f65fc
- Child:
- 1:c636842ce79c
Display Oled Driver SSD1306 I2C 128x64
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
franni | 0:3b87797f65fc | 1 | #include "mbed.h" |
franni | 0:3b87797f65fc | 2 | #include "Adafruit_SSD1306.h" |
franni | 0:3b87797f65fc | 3 | |
franni | 0:3b87797f65fc | 4 | DigitalOut led1(LED_RED); |
franni | 0:3b87797f65fc | 5 | |
franni | 0:3b87797f65fc | 6 | // SPI sub-class that provides a constructed default |
franni | 0:3b87797f65fc | 7 | class I2CPreInit : public I2C |
franni | 0:3b87797f65fc | 8 | { |
franni | 0:3b87797f65fc | 9 | public: |
franni | 0:3b87797f65fc | 10 | I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) |
franni | 0:3b87797f65fc | 11 | { |
franni | 0:3b87797f65fc | 12 | //frequency(400000); |
franni | 0:3b87797f65fc | 13 | frequency(100000); |
franni | 0:3b87797f65fc | 14 | start(); |
franni | 0:3b87797f65fc | 15 | }; |
franni | 0:3b87797f65fc | 16 | }; |
franni | 0:3b87797f65fc | 17 | |
franni | 0:3b87797f65fc | 18 | I2CPreInit myI2C(PTE0,PTE1); |
franni | 0:3b87797f65fc | 19 | Adafruit_SSD1306_I2c myOled(myI2C,NC,0x78,64,128); |
franni | 0:3b87797f65fc | 20 | |
franni | 0:3b87797f65fc | 21 | int main() |
franni | 0:3b87797f65fc | 22 | { |
franni | 0:3b87797f65fc | 23 | uint16_t x=0; |
franni | 0:3b87797f65fc | 24 | |
franni | 0:3b87797f65fc | 25 | myOled.begin(); |
franni | 0:3b87797f65fc | 26 | myOled.printf("%ux%u Hellow World\r\n", myOled.width(), myOled.height()); |
franni | 0:3b87797f65fc | 27 | myOled.display(); |
franni | 0:3b87797f65fc | 28 | |
franni | 0:3b87797f65fc | 29 | while(1) |
franni | 0:3b87797f65fc | 30 | { |
franni | 0:3b87797f65fc | 31 | led1 = !led1; |
franni | 0:3b87797f65fc | 32 | myOled.printf("%u\r",x); |
franni | 0:3b87797f65fc | 33 | myOled.display(); |
franni | 0:3b87797f65fc | 34 | x = x + 1; |
franni | 0:3b87797f65fc | 35 | wait(1.0); |
franni | 0:3b87797f65fc | 36 | } |
franni | 0:3b87797f65fc | 37 | } |
franni | 0:3b87797f65fc | 38 | |
franni | 0:3b87797f65fc | 39 | |
franni | 0:3b87797f65fc | 40 | |
franni | 0:3b87797f65fc | 41 | |
franni | 0:3b87797f65fc | 42 | |
franni | 0:3b87797f65fc | 43 | |
franni | 0:3b87797f65fc | 44 | /* |
franni | 0:3b87797f65fc | 45 | #include "mbed.h" |
franni | 0:3b87797f65fc | 46 | #include "Adafruit_SSD1306.h" |
franni | 0:3b87797f65fc | 47 | |
franni | 0:3b87797f65fc | 48 | class I2CPreInit : public I2C |
franni | 0:3b87797f65fc | 49 | { |
franni | 0:3b87797f65fc | 50 | public: |
franni | 0:3b87797f65fc | 51 | I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) |
franni | 0:3b87797f65fc | 52 | { |
franni | 0:3b87797f65fc | 53 | frequency(100000); |
franni | 0:3b87797f65fc | 54 | start(); |
franni | 0:3b87797f65fc | 55 | }; |
franni | 0:3b87797f65fc | 56 | }; |
franni | 0:3b87797f65fc | 57 | |
franni | 0:3b87797f65fc | 58 | I2CPreInit myI2C(PTE0,PTE1); |
franni | 0:3b87797f65fc | 59 | Adafruit_SSD1306_I2c myOled(myI2C,NC,0x78,64,128); |
franni | 0:3b87797f65fc | 60 | |
franni | 0:3b87797f65fc | 61 | int main() |
franni | 0:3b87797f65fc | 62 | { |
franni | 0:3b87797f65fc | 63 | |
franni | 0:3b87797f65fc | 64 | uint16_t x=0; |
franni | 0:3b87797f65fc | 65 | |
franni | 0:3b87797f65fc | 66 | myOled.begin(); |
franni | 0:3b87797f65fc | 67 | myOled.clearDisplay(); |
franni | 0:3b87797f65fc | 68 | myOled.display(); |
franni | 0:3b87797f65fc | 69 | wait(0.1); |
franni | 0:3b87797f65fc | 70 | |
franni | 0:3b87797f65fc | 71 | myOled.fillCircle(64, 42, 10, 1); |
franni | 0:3b87797f65fc | 72 | myOled.display(); |
franni | 0:3b87797f65fc | 73 | wait(1); |
franni | 0:3b87797f65fc | 74 | myOled.fillCircle(64, 42, 5, 0); |
franni | 0:3b87797f65fc | 75 | myOled.display(); |
franni | 0:3b87797f65fc | 76 | wait(1); |
franni | 0:3b87797f65fc | 77 | |
franni | 0:3b87797f65fc | 78 | myOled.clearDisplay(); |
franni | 0:3b87797f65fc | 79 | myOled.display(); |
franni | 0:3b87797f65fc | 80 | wait(0.1); |
franni | 0:3b87797f65fc | 81 | |
franni | 0:3b87797f65fc | 82 | myOled.printf("\r\n OLED %ux%u \r\n\r\n Hello World\r\n\n", myOled.width(), myOled.height()); |
franni | 0:3b87797f65fc | 83 | |
franni | 0:3b87797f65fc | 84 | myOled.drawRect(0, 0, 128, 64,1); |
franni | 0:3b87797f65fc | 85 | myOled.display(); |
franni | 0:3b87797f65fc | 86 | wait(0.5); |
franni | 0:3b87797f65fc | 87 | while(1) |
franni | 0:3b87797f65fc | 88 | { |
franni | 0:3b87797f65fc | 89 | |
franni | 0:3b87797f65fc | 90 | myOled.printf("%u\r ",x); |
franni | 0:3b87797f65fc | 91 | |
franni | 0:3b87797f65fc | 92 | myOled.drawRect(0, 0, 128, 64,1); |
franni | 0:3b87797f65fc | 93 | |
franni | 0:3b87797f65fc | 94 | myOled.display(); |
franni | 0:3b87797f65fc | 95 | x = x + 1; |
franni | 0:3b87797f65fc | 96 | wait(0.01); |
franni | 0:3b87797f65fc | 97 | } |
franni | 0:3b87797f65fc | 98 | } |
franni | 0:3b87797f65fc | 99 | */ |
franni | 0:3b87797f65fc | 100 | |
franni | 0:3b87797f65fc | 101 | |
franni | 0:3b87797f65fc | 102 | |
franni | 0:3b87797f65fc | 103 |