cagdas d
/
_uebung_demirtas_06102020
first commit
Revision 2:65f24e5a3ce4, committed 2020-10-06
- Comitter:
- kafka
- Date:
- Tue Oct 06 17:22:26 2020 +0000
- Parent:
- 1:0ab6ec2cda59
- Commit message:
- 3rd commit
Changed in this revision
MyClassB.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0ab6ec2cda59 -r 65f24e5a3ce4 MyClassB.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyClassB.h Tue Oct 06 17:22:26 2020 +0000 @@ -0,0 +1,23 @@ + +class MyClassB +{ + public: + MyClassB(PinName sda, PinName scl) : i2c(sda, scl) {}; // I2C Pins übergeben p28, p27 + float read(); + + private: + I2C i2c; +}; + +float MyClassB::read() +{ + const int addr = 0x90; + char cmd[2]; + i2c.write(addr, cmd, 2); + wait(0.5); + cmd[0] = 0x00; + i2c.write(addr, cmd, 1); + i2c.read(addr, cmd, 2); + float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); + return tmp; +} \ No newline at end of file
diff -r 0ab6ec2cda59 -r 65f24e5a3ce4 main.cpp --- a/main.cpp Tue Oct 06 15:59:02 2020 +0000 +++ b/main.cpp Tue Oct 06 17:22:26 2020 +0000 @@ -1,22 +1,27 @@ #include "mbed.h" #include "MyClass.h" #include "MyClassA.h" +#include "MyClassB.h" DigitalOut led(LED1); +MyClass element1 (23.2); +MyClass element2; -int main() { - MyClass element1 (23.2); - MyClass element2; - - MyClassA element_A_1(42, false); - MyClassA element_A_2; - - while (1) { +MyClassA element_A_1(42, false); +MyClassA element_A_2; + +MyClassB sensor(p28, p27); + +int main() +{ + while (1) + { led = !led; printf("Blink! LED is now %d\n", led.read()); printf("element1 messwert: %lf, element2 messwert: %lf \n", element1.get_wert(), element2.get_wert()); printf("element_A_1 x: %d, element_A_2 x: %d \n", element_A_1.getX(), element_A_2.getX()); printf("element_A_1 wahr: %s, element_A_2 x: %s \n", element_A_1.getWahr() ? "wahr" : "false", element_A_2.getWahr() ? "wahr": "false"); + printf("sensor value %f\n", sensor.read()); wait_ms(500); } }