test
Dependencies: mbed Adafruit_GFX DS1820
main.cpp@0:eca6ced34e87, 2020-10-16 (annotated)
- Committer:
- wf
- Date:
- Fri Oct 16 10:42:10 2020 +0000
- Revision:
- 0:eca6ced34e87
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wf | 0:eca6ced34e87 | 1 | |
wf | 0:eca6ced34e87 | 2 | |
wf | 0:eca6ced34e87 | 3 | |
wf | 0:eca6ced34e87 | 4 | |
wf | 0:eca6ced34e87 | 5 | |
wf | 0:eca6ced34e87 | 6 | /* |
wf | 0:eca6ced34e87 | 7 | * Copyright (c) 2012 Neal Horman - http://www.wanlink.com |
wf | 0:eca6ced34e87 | 8 | * |
wf | 0:eca6ced34e87 | 9 | * License: MIT open source (http://opensource.org/licenses/MIT) |
wf | 0:eca6ced34e87 | 10 | * Summary; |
wf | 0:eca6ced34e87 | 11 | * Use / modify / distribute / publish it how you want and |
wf | 0:eca6ced34e87 | 12 | * if you use it, or don't, you can't hold me liable for how |
wf | 0:eca6ced34e87 | 13 | * it does or doesn't work. |
wf | 0:eca6ced34e87 | 14 | * If it doesn't work how you want, don't use it, or change |
wf | 0:eca6ced34e87 | 15 | * it so that it does work. |
wf | 0:eca6ced34e87 | 16 | */ |
wf | 0:eca6ced34e87 | 17 | |
wf | 0:eca6ced34e87 | 18 | #include "mbed.h" |
wf | 0:eca6ced34e87 | 19 | #include "Adafruit_SSD1306.h" |
wf | 0:eca6ced34e87 | 20 | #include "DS1820.h" |
wf | 0:eca6ced34e87 | 21 | |
wf | 0:eca6ced34e87 | 22 | |
wf | 0:eca6ced34e87 | 23 | |
wf | 0:eca6ced34e87 | 24 | |
wf | 0:eca6ced34e87 | 25 | //****** Definitionen ********************** |
wf | 0:eca6ced34e87 | 26 | Serial pc(SERIAL_TX,SERIAL_RX); //nucleo |
wf | 0:eca6ced34e87 | 27 | |
wf | 0:eca6ced34e87 | 28 | // DS1820 Temperatursensor |
wf | 0:eca6ced34e87 | 29 | #define DATA_PIN A0 // DS18B20 |
wf | 0:eca6ced34e87 | 30 | DS1820 ds1820(DATA_PIN); // create a ds1820 sensor |
wf | 0:eca6ced34e87 | 31 | |
wf | 0:eca6ced34e87 | 32 | |
wf | 0:eca6ced34e87 | 33 | // an I2C sub-class that provides a constructed default |
wf | 0:eca6ced34e87 | 34 | class I2CPreInit : public I2C |
wf | 0:eca6ced34e87 | 35 | { |
wf | 0:eca6ced34e87 | 36 | public: |
wf | 0:eca6ced34e87 | 37 | I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) |
wf | 0:eca6ced34e87 | 38 | { |
wf | 0:eca6ced34e87 | 39 | frequency(400000); |
wf | 0:eca6ced34e87 | 40 | start(); |
wf | 0:eca6ced34e87 | 41 | }; |
wf | 0:eca6ced34e87 | 42 | }; |
wf | 0:eca6ced34e87 | 43 | |
wf | 0:eca6ced34e87 | 44 | |
wf | 0:eca6ced34e87 | 45 | |
wf | 0:eca6ced34e87 | 46 | I2CPreInit gI2C(D4,D5); |
wf | 0:eca6ced34e87 | 47 | Adafruit_SSD1306_I2c gOled2(gI2C,NC,0x78,64,128); |
wf | 0:eca6ced34e87 | 48 | // NC not connected |
wf | 0:eca6ced34e87 | 49 | // 0x78 i2c adress |
wf | 0:eca6ced34e87 | 50 | // 64x128 auflösung |
wf | 0:eca6ced34e87 | 51 | int main() |
wf | 0:eca6ced34e87 | 52 | { uint16_t x=0; |
wf | 0:eca6ced34e87 | 53 | |
wf | 0:eca6ced34e87 | 54 | |
wf | 0:eca6ced34e87 | 55 | |
wf | 0:eca6ced34e87 | 56 | |
wf | 0:eca6ced34e87 | 57 | // Invert Display |
wf | 0:eca6ced34e87 | 58 | //display.invertDisplay(1); |
wf | 0:eca6ced34e87 | 59 | |
wf | 0:eca6ced34e87 | 60 | |
wf | 0:eca6ced34e87 | 61 | // gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height()); |
wf | 0:eca6ced34e87 | 62 | |
wf | 0:eca6ced34e87 | 63 | while(1) |
wf | 0:eca6ced34e87 | 64 | { |
wf | 0:eca6ced34e87 | 65 | gOled2.printf("%u\r",x); |
wf | 0:eca6ced34e87 | 66 | gOled2.display(); |
wf | 0:eca6ced34e87 | 67 | x++; |
wf | 0:eca6ced34e87 | 68 | wait(1.0); |
wf | 0:eca6ced34e87 | 69 | |
wf | 0:eca6ced34e87 | 70 | //DS18B20 |
wf | 0:eca6ced34e87 | 71 | if(ds1820.begin()) |
wf | 0:eca6ced34e87 | 72 | { |
wf | 0:eca6ced34e87 | 73 | ds1820.startConversion(); // start temperature conversion |
wf | 0:eca6ced34e87 | 74 | wait(1.0); // let DS1820 complete the temperature conversion |
wf | 0:eca6ced34e87 | 75 | pc.printf("temprature DS1820 = %3.1f ^C\r\n", ds1820.read(),248); // read temperature |
wf | 0:eca6ced34e87 | 76 | pc.printf("__________________\r\n"); |
wf | 0:eca6ced34e87 | 77 | gOled2.printf("DS1820 = %3.1f ^C\r\n",ds1820.read()); |
wf | 0:eca6ced34e87 | 78 | } |
wf | 0:eca6ced34e87 | 79 | else |
wf | 0:eca6ced34e87 | 80 | { |
wf | 0:eca6ced34e87 | 81 | pc.printf("No DS1820 sensor found!\r\n"); |
wf | 0:eca6ced34e87 | 82 | } |
wf | 0:eca6ced34e87 | 83 | |
wf | 0:eca6ced34e87 | 84 | |
wf | 0:eca6ced34e87 | 85 | |
wf | 0:eca6ced34e87 | 86 | } |
wf | 0:eca6ced34e87 | 87 | } |
wf | 0:eca6ced34e87 | 88 | |
wf | 0:eca6ced34e87 | 89 |