![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Nucleo_L432_OLED_ADC
Dependencies: Adafruit_GFX mbed
main.cpp@4:573208af69ba, 2016-10-27 (annotated)
- Committer:
- pythonworld
- Date:
- Thu Oct 27 13:35:03 2016 +0000
- Revision:
- 4:573208af69ba
- Parent:
- 3:85bd3daf17ff
- Child:
- 5:e4f8eaef10c6
AXDL335 support
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:573208af69ba | 11 | #define offset_voltage 1570 |
pythonworld | 4:573208af69ba | 12 | #define sensitivity 330 |
pythonworld | 0:e96c4a26bee6 | 13 | Serial pc(SERIAL_TX, SERIAL_RX); |
pythonworld | 3:85bd3daf17ff | 14 | |
pythonworld | 0:e96c4a26bee6 | 15 | DigitalOut myled(LED3); |
pythonworld | 3:85bd3daf17ff | 16 | AnalogIn adc1(A0); |
pythonworld | 3:85bd3daf17ff | 17 | AnalogIn adc2(A1); |
pythonworld | 3:85bd3daf17ff | 18 | AnalogIn adc3(A5); |
pythonworld | 0:e96c4a26bee6 | 19 | |
pythonworld | 0:e96c4a26bee6 | 20 | #define DO A4 |
pythonworld | 0:e96c4a26bee6 | 21 | #define DI A6 |
pythonworld | 0:e96c4a26bee6 | 22 | #define CS D9 |
pythonworld | 3:85bd3daf17ff | 23 | #define DC D11 |
pythonworld | 0:e96c4a26bee6 | 24 | #define RST D7 |
pythonworld | 0:e96c4a26bee6 | 25 | |
pythonworld | 0:e96c4a26bee6 | 26 | class SPIPreInit : public SPI |
pythonworld | 0:e96c4a26bee6 | 27 | { |
pythonworld | 0:e96c4a26bee6 | 28 | public: |
pythonworld | 0:e96c4a26bee6 | 29 | SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { |
pythonworld | 0:e96c4a26bee6 | 30 | format(8,3); |
pythonworld | 0:e96c4a26bee6 | 31 | frequency(2000000); |
pythonworld | 0:e96c4a26bee6 | 32 | }; |
pythonworld | 0:e96c4a26bee6 | 33 | }; |
pythonworld | 3:85bd3daf17ff | 34 | |
pythonworld | 0:e96c4a26bee6 | 35 | SPIPreInit mySpi(DI,NC,DO); |
pythonworld | 0:e96c4a26bee6 | 36 | Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128); |
pythonworld | 0:e96c4a26bee6 | 37 | |
pythonworld | 3:85bd3daf17ff | 38 | |
pythonworld | 3:85bd3daf17ff | 39 | |
pythonworld | 3:85bd3daf17ff | 40 | int main() |
pythonworld | 3:85bd3daf17ff | 41 | { |
pythonworld | 3:85bd3daf17ff | 42 | int x=0; |
pythonworld | 3:85bd3daf17ff | 43 | |
pythonworld | 3:85bd3daf17ff | 44 | |
pythonworld | 3:85bd3daf17ff | 45 | oled.clearDisplay(); |
pythonworld | 3:85bd3daf17ff | 46 | oled.setTextSize(2); |
pythonworld | 3:85bd3daf17ff | 47 | while(1) { |
pythonworld | 3:85bd3daf17ff | 48 | x++; |
pythonworld | 4:573208af69ba | 49 | oled.printf("X %2.2lf g\r\n",double(adc1.read()*3300-offset_voltage)/sensitivity); |
pythonworld | 4:573208af69ba | 50 | oled.printf("Y %2.2lf g\r\n",double(adc2.read()*3300-offset_voltage)/sensitivity); |
pythonworld | 4:573208af69ba | 51 | oled.printf("Z %2.2lf g\r\n",double(adc3.read()*3300-offset_voltage)/sensitivity); |
pythonworld | 3:85bd3daf17ff | 52 | |
pythonworld | 3:85bd3daf17ff | 53 | oled.display(); |
pythonworld | 3:85bd3daf17ff | 54 | wait(0.5); |
pythonworld | 3:85bd3daf17ff | 55 | |
pythonworld | 3:85bd3daf17ff | 56 | pc.printf("X %2.3f V\r\n", adc1.read()*3300/1000); |
pythonworld | 3:85bd3daf17ff | 57 | pc.printf("Y %2.3f V\r\n", adc2.read()*3300/1000); |
pythonworld | 3:85bd3daf17ff | 58 | pc.printf("Z %2.3f V\r\n", adc3.read()*3300/1000); |
pythonworld | 3:85bd3daf17ff | 59 | |
pythonworld | 3:85bd3daf17ff | 60 | // myled = !myled; |
pythonworld | 3:85bd3daf17ff | 61 | if(x>0) { |
pythonworld | 3:85bd3daf17ff | 62 | oled.setTextCursor(0,0); |
pythonworld | 3:85bd3daf17ff | 63 | oled.clearDisplay(); |
pythonworld | 3:85bd3daf17ff | 64 | x=0; |
pythonworld | 3:85bd3daf17ff | 65 | } |
pythonworld | 3:85bd3daf17ff | 66 | } |
pythonworld | 0:e96c4a26bee6 | 67 | } |