Nucleo_L432_OLED_ADC

Dependencies:   Adafruit_GFX mbed

main.cpp

Committer:
pythonworld
Date:
2016-10-26
Revision:
3:85bd3daf17ff
Parent:
2:730476ff1e87
Child:
4:573208af69ba

File content as of revision 3:85bd3daf17ff:

#include "mbed.h"
#include "Adafruit_SSD1306.h"
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

// SSD1306 OLED AND Nucleo L432KC
// 2016.10.23
// 2016.10.23 changed
Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED3);
AnalogIn adc1(A0);
AnalogIn adc2(A1);
AnalogIn adc3(A5);

#define DO A4
#define DI A6
#define CS D9
#define DC D11
#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 x=0;


    oled.clearDisplay();
    oled.setTextSize(2);
    while(1) {
        x++;
        oled.printf("X %2.3f V\r\n",adc1.read()*3300/1000);
        oled.printf("Y %2.3f V\r\n",adc2.read()*3300/1000);
        oled.printf("Z %2.3f V\r\n",adc3.read()*3300/1000);

        oled.display();
        wait(0.5);

        pc.printf("X %2.3f V\r\n", adc1.read()*3300/1000);
        pc.printf("Y %2.3f V\r\n", adc2.read()*3300/1000);
        pc.printf("Z %2.3f V\r\n", adc3.read()*3300/1000);

//  myled = !myled;
        if(x>0) {
            oled.setTextCursor(0,0);
            oled.clearDisplay();
            x=0;
        }
    }
}