![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
1.3''OLED
Dependencies: mbed QEI OLED_SSD1306_SH1106 I2C_SSD1306_nucleo_l432KC
main.cpp
- Committer:
- aiyazaole
- Date:
- 2022-05-27
- Revision:
- 16:a72f4818d591
- Parent:
- 14:d7bc532b2133
File content as of revision 16:a72f4818d591:
#include "mbed.h" #include "Adafruit_SSD1306.h" #include "QEI.h" I2C i2c(PA_10,PA_9); Adafruit_SH1106_I2c myOled(i2c,NC,0x78,64,128); QEI EnB(D5,D6,NC,500,QEI::X4_ENCODING);//4倍编码器 //QEI EnB(PA_5,PA_6,NC,500);//2倍编码器 int main() { //i2c.frequency(100000); i2c.start(); myOled.begin(); myOled.display(); wait(0.5); myOled.clearDisplay(); //myOled.setTextColor(1); myOled.setTextSize(3); myOled.printf("Du long\r"); int oldPosition = -1; int newposition; while(1) { newposition = EnB.getPulses(); if (oldPosition == -1) { myOled.setTextCursor(40,32); myOled.setTextSize(2); myOled.printf("ready!\r"); myOled.display(); } if (newposition < 0) newposition = -newposition; if (newposition > oldPosition) { myOled.clearDisplay(); oldPosition = newposition; myOled.setTextCursor(40,32); myOled.setTextSize(3); myOled.printf("%d\r",oldPosition); myOled.display(); } } }