
This is a remote control tester, it uses a CNC, Ethernet Communication with a JAVAFX interface and a PLC in order to control some valves.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of CNC_CONTROLLER by
PCF8574.cpp@2:835c883d81b0, 2017-12-15 (annotated)
- Committer:
- kevencastro7
- Date:
- Fri Dec 15 19:40:41 2017 +0000
- Revision:
- 2:835c883d81b0
This is a remote control tester, it uses a CNC, Ethernet Communication with a JAVAFX interface and a PLC in order to control some valves.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevencastro7 | 2:835c883d81b0 | 1 | #include "PCF8574.h" |
kevencastro7 | 2:835c883d81b0 | 2 | #include "mbed.h" |
kevencastro7 | 2:835c883d81b0 | 3 | |
kevencastro7 | 2:835c883d81b0 | 4 | PCF8574::PCF8574(PinName sda, PinName scl, int address) |
kevencastro7 | 2:835c883d81b0 | 5 | : _i2c(sda, scl) { |
kevencastro7 | 2:835c883d81b0 | 6 | _address = address; |
kevencastro7 | 2:835c883d81b0 | 7 | } |
kevencastro7 | 2:835c883d81b0 | 8 | |
kevencastro7 | 2:835c883d81b0 | 9 | int PCF8574::read(int port) { |
kevencastro7 | 2:835c883d81b0 | 10 | char foo[1]; |
kevencastro7 | 2:835c883d81b0 | 11 | int num,r,i=0; |
kevencastro7 | 2:835c883d81b0 | 12 | int bin[8]; |
kevencastro7 | 2:835c883d81b0 | 13 | _i2c.read(_address, foo, 1); |
kevencastro7 | 2:835c883d81b0 | 14 | num = foo[0]; |
kevencastro7 | 2:835c883d81b0 | 15 | while(num!=0){ |
kevencastro7 | 2:835c883d81b0 | 16 | r = num%2; |
kevencastro7 | 2:835c883d81b0 | 17 | bin[i++] = r; |
kevencastro7 | 2:835c883d81b0 | 18 | num /= 2; |
kevencastro7 | 2:835c883d81b0 | 19 | } |
kevencastro7 | 2:835c883d81b0 | 20 | return(bin[port]); |
kevencastro7 | 2:835c883d81b0 | 21 | } |
kevencastro7 | 2:835c883d81b0 | 22 | |
kevencastro7 | 2:835c883d81b0 | 23 | void PCF8574::write(int data) { |
kevencastro7 | 2:835c883d81b0 | 24 | char foo[1]; |
kevencastro7 | 2:835c883d81b0 | 25 | foo[0] = data; |
kevencastro7 | 2:835c883d81b0 | 26 | _i2c.write(_address, foo, 1); |
kevencastro7 | 2:835c883d81b0 | 27 | } |
kevencastro7 | 2:835c883d81b0 | 28 |