Nucleo_L432_OLED_ADC
Dependencies: Adafruit_GFX mbed
main.cpp@0:e96c4a26bee6, 2016-10-22 (annotated)
- Committer:
- pythonworld
- Date:
- Sat Oct 22 23:03:56 2016 +0000
- Revision:
- 0:e96c4a26bee6
- Child:
- 1:0238bbba44a4
No more change
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 | 0:e96c4a26bee6 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
pythonworld | 0:e96c4a26bee6 | 9 | |
pythonworld | 0:e96c4a26bee6 | 10 | DigitalOut myled(LED3); |
pythonworld | 0:e96c4a26bee6 | 11 | AnalogIn adc(A0); |
pythonworld | 0:e96c4a26bee6 | 12 | |
pythonworld | 0:e96c4a26bee6 | 13 | #define DO A4 |
pythonworld | 0:e96c4a26bee6 | 14 | #define DI A6 |
pythonworld | 0:e96c4a26bee6 | 15 | #define CS D9 |
pythonworld | 0:e96c4a26bee6 | 16 | #define DC A1 |
pythonworld | 0:e96c4a26bee6 | 17 | #define RST D7 |
pythonworld | 0:e96c4a26bee6 | 18 | |
pythonworld | 0:e96c4a26bee6 | 19 | class SPIPreInit : public SPI |
pythonworld | 0:e96c4a26bee6 | 20 | { |
pythonworld | 0:e96c4a26bee6 | 21 | public: |
pythonworld | 0:e96c4a26bee6 | 22 | SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { |
pythonworld | 0:e96c4a26bee6 | 23 | format(8,3); |
pythonworld | 0:e96c4a26bee6 | 24 | frequency(2000000); |
pythonworld | 0:e96c4a26bee6 | 25 | }; |
pythonworld | 0:e96c4a26bee6 | 26 | }; |
pythonworld | 0:e96c4a26bee6 | 27 | |
pythonworld | 0:e96c4a26bee6 | 28 | SPIPreInit mySpi(DI,NC,DO); |
pythonworld | 0:e96c4a26bee6 | 29 | Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128); |
pythonworld | 0:e96c4a26bee6 | 30 | |
pythonworld | 0:e96c4a26bee6 | 31 | |
pythonworld | 0:e96c4a26bee6 | 32 | |
pythonworld | 0:e96c4a26bee6 | 33 | int main() { |
pythonworld | 0:e96c4a26bee6 | 34 | int i = 1; |
pythonworld | 0:e96c4a26bee6 | 35 | int x =0; |
pythonworld | 0:e96c4a26bee6 | 36 | oled.clearDisplay(); |
pythonworld | 0:e96c4a26bee6 | 37 | oled.setTextSize(2); |
pythonworld | 0:e96c4a26bee6 | 38 | while(1) { |
pythonworld | 0:e96c4a26bee6 | 39 | |
pythonworld | 0:e96c4a26bee6 | 40 | |
pythonworld | 0:e96c4a26bee6 | 41 | x++; |
pythonworld | 0:e96c4a26bee6 | 42 | oled.printf("%d %2.3f V\r\n", x, adc.read()*3300/1000); |
pythonworld | 0:e96c4a26bee6 | 43 | oled.display(); |
pythonworld | 0:e96c4a26bee6 | 44 | wait(0.5); |
pythonworld | 0:e96c4a26bee6 | 45 | pc.printf("%d %2.3f V\r\n", i++, adc.read()*3300/1000); |
pythonworld | 0:e96c4a26bee6 | 46 | myled = !myled; |
pythonworld | 0:e96c4a26bee6 | 47 | if(x>3) { |
pythonworld | 0:e96c4a26bee6 | 48 | oled.setTextCursor(0,0); |
pythonworld | 0:e96c4a26bee6 | 49 | oled.clearDisplay(); |
pythonworld | 0:e96c4a26bee6 | 50 | x=0; |
pythonworld | 0:e96c4a26bee6 | 51 | } |
pythonworld | 0:e96c4a26bee6 | 52 | } |
pythonworld | 0:e96c4a26bee6 | 53 | } |
pythonworld | 0:e96c4a26bee6 | 54 |