Nucleo_L432_OLED_ADC
Dependencies: Adafruit_GFX mbed
main.cpp@5:e4f8eaef10c6, 2017-06-02 (annotated)
- Committer:
- pythonworld
- Date:
- Fri Jun 02 00:27:26 2017 +0000
- Revision:
- 5:e4f8eaef10c6
- Parent:
- 4:573208af69ba
only ADXL335 support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pythonworld | 0:e96c4a26bee6 | 1 | #include "mbed.h" |
pythonworld | 5:e4f8eaef10c6 | 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 | 5:e4f8eaef10c6 | 7 | // SSD1306 OLED AND Nucleo L432KC |
pythonworld | 0:e96c4a26bee6 | 8 | |
pythonworld | 5:e4f8eaef10c6 | 9 | #define Number 2048 |
pythonworld | 5:e4f8eaef10c6 | 10 | #define XS 0.3235 |
pythonworld | 5:e4f8eaef10c6 | 11 | #define YS 0.3235 |
pythonworld | 5:e4f8eaef10c6 | 12 | #define ZS 0.3200 |
pythonworld | 5:e4f8eaef10c6 | 13 | #define XB 1.5675 |
pythonworld | 5:e4f8eaef10c6 | 14 | #define YB 1.5465 |
pythonworld | 5:e4f8eaef10c6 | 15 | #define ZB 1.6100 |
pythonworld | 0:e96c4a26bee6 | 16 | |
pythonworld | 0:e96c4a26bee6 | 17 | #define DO A4 |
pythonworld | 0:e96c4a26bee6 | 18 | #define DI A6 |
pythonworld | 0:e96c4a26bee6 | 19 | #define CS D9 |
pythonworld | 3:85bd3daf17ff | 20 | #define DC D11 |
pythonworld | 0:e96c4a26bee6 | 21 | #define RST D7 |
pythonworld | 0:e96c4a26bee6 | 22 | |
pythonworld | 5:e4f8eaef10c6 | 23 | Serial pc(SERIAL_TX, SERIAL_RX); |
pythonworld | 5:e4f8eaef10c6 | 24 | DigitalOut myled(LED3); |
pythonworld | 5:e4f8eaef10c6 | 25 | AnalogIn adc1(A0); |
pythonworld | 5:e4f8eaef10c6 | 26 | AnalogIn adc2(A1); |
pythonworld | 5:e4f8eaef10c6 | 27 | AnalogIn adc3(A5); |
pythonworld | 5:e4f8eaef10c6 | 28 | float xa[Number],ya[Number],za[Number]; |
pythonworld | 5:e4f8eaef10c6 | 29 | |
pythonworld | 5:e4f8eaef10c6 | 30 | |
pythonworld | 3:85bd3daf17ff | 31 | |
pythonworld | 5:e4f8eaef10c6 | 32 | // |
pythonworld | 5:e4f8eaef10c6 | 33 | //class SPIPreInit : public SPI |
pythonworld | 5:e4f8eaef10c6 | 34 | //{ |
pythonworld | 5:e4f8eaef10c6 | 35 | //public: |
pythonworld | 5:e4f8eaef10c6 | 36 | // SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { |
pythonworld | 5:e4f8eaef10c6 | 37 | // format(8,3); |
pythonworld | 5:e4f8eaef10c6 | 38 | // frequency(2000000); |
pythonworld | 5:e4f8eaef10c6 | 39 | // }; |
pythonworld | 5:e4f8eaef10c6 | 40 | //}; |
pythonworld | 5:e4f8eaef10c6 | 41 | // |
pythonworld | 5:e4f8eaef10c6 | 42 | //SPIPreInit mySpi(DI,NC,DO); |
pythonworld | 5:e4f8eaef10c6 | 43 | //Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128); |
pythonworld | 0:e96c4a26bee6 | 44 | |
pythonworld | 3:85bd3daf17ff | 45 | |
pythonworld | 3:85bd3daf17ff | 46 | |
pythonworld | 3:85bd3daf17ff | 47 | int main() |
pythonworld | 3:85bd3daf17ff | 48 | { |
pythonworld | 3:85bd3daf17ff | 49 | int x=0; |
pythonworld | 3:85bd3daf17ff | 50 | |
pythonworld | 3:85bd3daf17ff | 51 | |
pythonworld | 5:e4f8eaef10c6 | 52 | // oled.clearDisplay(); |
pythonworld | 5:e4f8eaef10c6 | 53 | // oled.setTextSize(2); |
pythonworld | 5:e4f8eaef10c6 | 54 | |
pythonworld | 3:85bd3daf17ff | 55 | while(1) { |
pythonworld | 5:e4f8eaef10c6 | 56 | |
pythonworld | 5:e4f8eaef10c6 | 57 | // oled.printf("X %2.2lf g\r\n",double(adc1.read()*3300-offset_voltage)/sensitivity); |
pythonworld | 5:e4f8eaef10c6 | 58 | // oled.printf("Y %2.2lf g\r\n",double(adc2.read()*3300-offset_voltage)/sensitivity); |
pythonworld | 5:e4f8eaef10c6 | 59 | // oled.printf("Z %2.2lf g\r\n",double(adc3.read()*3300-offset_voltage)/sensitivity); |
pythonworld | 5:e4f8eaef10c6 | 60 | // oled.display(); |
pythonworld | 5:e4f8eaef10c6 | 61 | |
pythonworld | 5:e4f8eaef10c6 | 62 | wait_us(500); |
pythonworld | 5:e4f8eaef10c6 | 63 | |
pythonworld | 5:e4f8eaef10c6 | 64 | xa[x]=adc1.read()*3300/1000; |
pythonworld | 5:e4f8eaef10c6 | 65 | ya[x]=adc2.read()*3300/1000; |
pythonworld | 5:e4f8eaef10c6 | 66 | za[x]=adc3.read()*3300/1000; |
pythonworld | 3:85bd3daf17ff | 67 | |
pythonworld | 5:e4f8eaef10c6 | 68 | x++; |
pythonworld | 5:e4f8eaef10c6 | 69 | myled = !myled; |
pythonworld | 5:e4f8eaef10c6 | 70 | |
pythonworld | 5:e4f8eaef10c6 | 71 | if(x>=Number) { |
pythonworld | 3:85bd3daf17ff | 72 | |
pythonworld | 5:e4f8eaef10c6 | 73 | myled = !myled; |
pythonworld | 5:e4f8eaef10c6 | 74 | int c=0; |
pythonworld | 5:e4f8eaef10c6 | 75 | while(c++<1) { |
pythonworld | 3:85bd3daf17ff | 76 | |
pythonworld | 5:e4f8eaef10c6 | 77 | pc.printf("X %2.3f g\r\n", (xa[c]-XB)/XS); |
pythonworld | 5:e4f8eaef10c6 | 78 | pc.printf("Y %2.3f g\r\n", (ya[c]-YB)/YS); |
pythonworld | 5:e4f8eaef10c6 | 79 | pc.printf("Z %2.3f g\r\n", (za[c]-ZB)/ZS); |
pythonworld | 5:e4f8eaef10c6 | 80 | pc.printf("-----------------\r\n"); |
pythonworld | 5:e4f8eaef10c6 | 81 | |
pythonworld | 5:e4f8eaef10c6 | 82 | wait(2); |
pythonworld | 5:e4f8eaef10c6 | 83 | } |
pythonworld | 3:85bd3daf17ff | 84 | x=0; |
pythonworld | 3:85bd3daf17ff | 85 | } |
pythonworld | 3:85bd3daf17ff | 86 | } |
pythonworld | 0:e96c4a26bee6 | 87 | } |