Nucleo_L432_OLED_ADC

Dependencies:   Adafruit_GFX mbed

Revision:
0:e96c4a26bee6
Child:
1:0238bbba44a4
diff -r 000000000000 -r e96c4a26bee6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Oct 22 23:03:56 2016 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#include "Adafruit_SSD1306.h"
+//------------------------------------
+// Hyperterminal configuration
+// 9600 bauds, 8-bit data, no parity
+//------------------------------------
+
+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;
+  }
+  }
+}
+ 
\ No newline at end of file