在线时间409 小时
UID3006061
注册时间2015-3-23
NXP金币1248
TA的每日心情 | 开心 昨天 12:01 |
---|
签到天数: 819 天 [LV.10]以坛为家III
金牌会员
- 积分
- 5518
- 最后登录
- 2024-4-26
|
正准备用这个板子来调试飞凌的开发板,采购的一些配件还在路上,比较慢,趁着这个期间,研究一下点亮oled屏。采用mbed os非常容易点亮各种接口的oled屏,下边记录一下过程。
1. 先引入库Adafruit_GFX,直接搜索既可
2. 新建一个main.cpp并加入代码
- /*
- * 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"
-
- DigitalOut myled(LED1);
-
- // an SPI sub-class that provides a constructed default
- class SPIPreInit : public SPI
- {
- public:
- SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk)
- {
- format(8,3);
- frequency(2000000);
- };
- };
-
- // an I2C sub-class that provides a constructed default
- class I2CPreInit : public I2C
- {
- public:
- I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
- {
- //frequency(400000);
- frequency(400000);
- start();
- };
- };
-
- //SPIPreInit gSpi(p5,NC,p7);
- //Adafruit_SSD1306_Spi gOled1(gSpi,p26,p25,p24);
-
- I2CPreInit gI2C(P0_5,P0_4);
- Adafruit_SSD1306_I2c gOled2(gI2C,NC);
-
- int main()
- { uint16_t x=0;
-
- //gOled1.printf("%ux%u OLED Display\r\n", gOled1.width(), gOled1.height());
- gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height());
-
- while(1)
- {
- myled = !myled;
- // gOled1.printf("%u\r",x);
- // gOled1.display();
- gOled2.printf("%u\r",x);
- gOled2.display();
- x++;
- wait(1.0);
- }
- }
复制代码 3.把下载的文件拷贝到MBED盘,等待提示,然后重新插拔usb线,即可看到点亮了oled。
通过以上几步非常简单的点亮了oled,可见mbed变成也是非常便利的
|
|