Besa Mavriqi
/
Mbed_Dig_Out_Class_Reffernce
Mbed
Mbed_Dig_Out_Class_Reffernce.cpp@0:645b1d3bcc9d, 2020-01-14 (annotated)
- Committer:
- besam
- Date:
- Tue Jan 14 23:09:29 2020 +0000
- Revision:
- 0:645b1d3bcc9d
Letzte Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
besam | 0:645b1d3bcc9d | 1 | #include "mbed.h" |
besam | 0:645b1d3bcc9d | 2 | |
besam | 0:645b1d3bcc9d | 3 | DigitalOut led1(LED1); // Create a DigitalOut connected to the specified pin. |
besam | 0:645b1d3bcc9d | 4 | DigitalOut led2(LED2, 0); // Create a DigitalOut connected to the specified pin and initialize with 0 |
besam | 0:645b1d3bcc9d | 5 | DigitalOut led3(LED3); |
besam | 0:645b1d3bcc9d | 6 | DigitalOut led4(LED4); |
besam | 0:645b1d3bcc9d | 7 | |
besam | 0:645b1d3bcc9d | 8 | int value = 1; |
besam | 0:645b1d3bcc9d | 9 | |
besam | 0:645b1d3bcc9d | 10 | int main(void) { |
besam | 0:645b1d3bcc9d | 11 | led1.write(1); // Set the output, specified as 0 or 1 (int) |
besam | 0:645b1d3bcc9d | 12 | led2 = 1; // DigitalOut & operator= (int value) - A shorthand for write() |
besam | 0:645b1d3bcc9d | 13 | led3 = value; // DigitalOut & operator= (int value) - A shorthand for write() |
besam | 0:645b1d3bcc9d | 14 | led4 = led3; // DigitalOut & operator= (DigitalOut &rhs) - A shorthand for write() using the assignment operator which copies the state from the DigitalOut argument. |
besam | 0:645b1d3bcc9d | 15 | |
besam | 0:645b1d3bcc9d | 16 | if(led2.is_connected ()) { // Return the output setting, represented as 0 or 1 |
besam | 0:645b1d3bcc9d | 17 | if(led2.read() ) // Return the output setting, represented as 0 or 1 (int) |
besam | 0:645b1d3bcc9d | 18 | printf("%d %d\n", led1.read(), led2.read()); |
besam | 0:645b1d3bcc9d | 19 | } |
besam | 0:645b1d3bcc9d | 20 | if(led2) // operator int () - A shorthand for read() |
besam | 0:645b1d3bcc9d | 21 | printf("%d %d\n", led3.read(), led4.read()); |
besam | 0:645b1d3bcc9d | 22 | |
besam | 0:645b1d3bcc9d | 23 | return 0; |
besam | 0:645b1d3bcc9d | 24 | } |