Nucleo_L432_OLED_ADC
Dependencies: Adafruit_GFX mbed
main.cpp
- Committer:
- pythonworld
- Date:
- 2016-10-22
- Revision:
- 1:0238bbba44a4
- Parent:
- 0:e96c4a26bee6
- Child:
- 2:730476ff1e87
File content as of revision 1:0238bbba44a4:
#include "mbed.h" #include "Adafruit_SSD1306.h" //------------------------------------ // Hyperterminal configuration // 9600 bauds, 8-bit data, no parity //------------------------------------ // SSD1306 OLED AND Nucleo L432KC // 2016.10.23 // Serial pc(SERIAL_TX, SERIAL_RX); DigitalOut myled(LED3); AnalogIn adc(A0); #define DO A4 #define DI A6 #define CS D9 #define DC A1 #define RST D7 class SPIPreInit : public SPI { public: SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { format(8,3); frequency(2000000); }; }; SPIPreInit mySpi(DI,NC,DO); Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128); int main() { int i = 1; int x =0; oled.clearDisplay(); oled.setTextSize(2); while(1) { x++; oled.printf("%d %2.3f V\r\n", x, adc.read()*3300/1000); oled.display(); wait(0.5); pc.printf("%d %2.3f V\r\n", i++, adc.read()*3300/1000); myled = !myled; if(x>3) { oled.setTextCursor(0,0); oled.clearDisplay(); x=0; } } }