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