Nucleo_L432_OLED_ADC

Dependencies:   Adafruit_GFX mbed

Committer:
pythonworld
Date:
Wed Oct 26 12:38:47 2016 +0000
Revision:
3:85bd3daf17ff
Parent:
2:730476ff1e87
Child:
4:573208af69ba
three channels ADC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pythonworld 0:e96c4a26bee6 1 #include "mbed.h"
pythonworld 0:e96c4a26bee6 2 #include "Adafruit_SSD1306.h"
pythonworld 0:e96c4a26bee6 3 //------------------------------------
pythonworld 0:e96c4a26bee6 4 // Hyperterminal configuration
pythonworld 0:e96c4a26bee6 5 // 9600 bauds, 8-bit data, no parity
pythonworld 0:e96c4a26bee6 6 //------------------------------------
pythonworld 0:e96c4a26bee6 7
pythonworld 1:0238bbba44a4 8 // SSD1306 OLED AND Nucleo L432KC
pythonworld 1:0238bbba44a4 9 // 2016.10.23
pythonworld 2:730476ff1e87 10 // 2016.10.23 changed
pythonworld 0:e96c4a26bee6 11 Serial pc(SERIAL_TX, SERIAL_RX);
pythonworld 3:85bd3daf17ff 12
pythonworld 0:e96c4a26bee6 13 DigitalOut myled(LED3);
pythonworld 3:85bd3daf17ff 14 AnalogIn adc1(A0);
pythonworld 3:85bd3daf17ff 15 AnalogIn adc2(A1);
pythonworld 3:85bd3daf17ff 16 AnalogIn adc3(A5);
pythonworld 0:e96c4a26bee6 17
pythonworld 0:e96c4a26bee6 18 #define DO A4
pythonworld 0:e96c4a26bee6 19 #define DI A6
pythonworld 0:e96c4a26bee6 20 #define CS D9
pythonworld 3:85bd3daf17ff 21 #define DC D11
pythonworld 0:e96c4a26bee6 22 #define RST D7
pythonworld 0:e96c4a26bee6 23
pythonworld 0:e96c4a26bee6 24 class SPIPreInit : public SPI
pythonworld 0:e96c4a26bee6 25 {
pythonworld 0:e96c4a26bee6 26 public:
pythonworld 0:e96c4a26bee6 27 SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) {
pythonworld 0:e96c4a26bee6 28 format(8,3);
pythonworld 0:e96c4a26bee6 29 frequency(2000000);
pythonworld 0:e96c4a26bee6 30 };
pythonworld 0:e96c4a26bee6 31 };
pythonworld 3:85bd3daf17ff 32
pythonworld 0:e96c4a26bee6 33 SPIPreInit mySpi(DI,NC,DO);
pythonworld 0:e96c4a26bee6 34 Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128);
pythonworld 0:e96c4a26bee6 35
pythonworld 3:85bd3daf17ff 36
pythonworld 3:85bd3daf17ff 37
pythonworld 3:85bd3daf17ff 38 int main()
pythonworld 3:85bd3daf17ff 39 {
pythonworld 3:85bd3daf17ff 40 int x=0;
pythonworld 3:85bd3daf17ff 41
pythonworld 3:85bd3daf17ff 42
pythonworld 3:85bd3daf17ff 43 oled.clearDisplay();
pythonworld 3:85bd3daf17ff 44 oled.setTextSize(2);
pythonworld 3:85bd3daf17ff 45 while(1) {
pythonworld 3:85bd3daf17ff 46 x++;
pythonworld 3:85bd3daf17ff 47 oled.printf("X %2.3f V\r\n",adc1.read()*3300/1000);
pythonworld 3:85bd3daf17ff 48 oled.printf("Y %2.3f V\r\n",adc2.read()*3300/1000);
pythonworld 3:85bd3daf17ff 49 oled.printf("Z %2.3f V\r\n",adc3.read()*3300/1000);
pythonworld 3:85bd3daf17ff 50
pythonworld 3:85bd3daf17ff 51 oled.display();
pythonworld 3:85bd3daf17ff 52 wait(0.5);
pythonworld 3:85bd3daf17ff 53
pythonworld 3:85bd3daf17ff 54 pc.printf("X %2.3f V\r\n", adc1.read()*3300/1000);
pythonworld 3:85bd3daf17ff 55 pc.printf("Y %2.3f V\r\n", adc2.read()*3300/1000);
pythonworld 3:85bd3daf17ff 56 pc.printf("Z %2.3f V\r\n", adc3.read()*3300/1000);
pythonworld 3:85bd3daf17ff 57
pythonworld 3:85bd3daf17ff 58 // myled = !myled;
pythonworld 3:85bd3daf17ff 59 if(x>0) {
pythonworld 3:85bd3daf17ff 60 oled.setTextCursor(0,0);
pythonworld 3:85bd3daf17ff 61 oled.clearDisplay();
pythonworld 3:85bd3daf17ff 62 x=0;
pythonworld 3:85bd3daf17ff 63 }
pythonworld 3:85bd3daf17ff 64 }
pythonworld 0:e96c4a26bee6 65 }