Tina Dokic
/
i2c-_pins_tinf_06-10-2020
tinf
main.cpp@0:5ca7c8550369, 2020-10-06 (annotated)
- Committer:
- tina_dokic
- Date:
- Tue Oct 06 17:25:44 2020 +0000
- Revision:
- 0:5ca7c8550369
tinf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tina_dokic | 0:5ca7c8550369 | 1 | #include "mbed.h" |
tina_dokic | 0:5ca7c8550369 | 2 | |
tina_dokic | 0:5ca7c8550369 | 3 | |
tina_dokic | 0:5ca7c8550369 | 4 | class MyClassB |
tina_dokic | 0:5ca7c8550369 | 5 | { |
tina_dokic | 0:5ca7c8550369 | 6 | public: |
tina_dokic | 0:5ca7c8550369 | 7 | MyClassB(PinName sda, PinName scl): _i2c (sda, scl) |
tina_dokic | 0:5ca7c8550369 | 8 | { |
tina_dokic | 0:5ca7c8550369 | 9 | _result =0; |
tina_dokic | 0:5ca7c8550369 | 10 | }// I2C Pins übergeben p28, p27 |
tina_dokic | 0:5ca7c8550369 | 11 | float read(); |
tina_dokic | 0:5ca7c8550369 | 12 | |
tina_dokic | 0:5ca7c8550369 | 13 | private: |
tina_dokic | 0:5ca7c8550369 | 14 | I2C _i2c; |
tina_dokic | 0:5ca7c8550369 | 15 | float _result; |
tina_dokic | 0:5ca7c8550369 | 16 | }; |
tina_dokic | 0:5ca7c8550369 | 17 | |
tina_dokic | 0:5ca7c8550369 | 18 | float MyClassB :: read(){ |
tina_dokic | 0:5ca7c8550369 | 19 | return _result; |
tina_dokic | 0:5ca7c8550369 | 20 | } |
tina_dokic | 0:5ca7c8550369 | 21 | |
tina_dokic | 0:5ca7c8550369 | 22 | |
tina_dokic | 0:5ca7c8550369 | 23 | |
tina_dokic | 0:5ca7c8550369 | 24 | MyClass myClass(0.0); |
tina_dokic | 0:5ca7c8550369 | 25 | MyClassB sensor(p28, p27); |
tina_dokic | 0:5ca7c8550369 | 26 | |
tina_dokic | 0:5ca7c8550369 | 27 | int main() |
tina_dokic | 0:5ca7c8550369 | 28 | { |
tina_dokic | 0:5ca7c8550369 | 29 | myClass.status(); |
tina_dokic | 0:5ca7c8550369 | 30 | wait_ms(500); |
tina_dokic | 0:5ca7c8550369 | 31 | |
tina_dokic | 0:5ca7c8550369 | 32 | printf("Sensorwert: %f\n", sensor.read()); |
tina_dokic | 0:5ca7c8550369 | 33 | |
tina_dokic | 0:5ca7c8550369 | 34 | } |