Slight changes to support specific application

Dependents:   ColourSensor

Fork of PCF8574 by Simon Ford

Committer:
jolyon
Date:
Thu Nov 10 16:56:33 2016 +0000
Revision:
2:6c22af0aafbb
Parent:
1:ec8da0c59403
If device does not ack the return data is 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:ab4e14b911ee 1 /* mbed PCF8574 Library, for driving the I2C I/O Expander
simon 0:ab4e14b911ee 2 * Copyright (c) 2008-2010, cstyles, sford
simon 0:ab4e14b911ee 3 *
simon 0:ab4e14b911ee 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:ab4e14b911ee 5 * of this software and associated documentation files (the "Software"), to deal
simon 0:ab4e14b911ee 6 * in the Software without restriction, including without limitation the rights
simon 0:ab4e14b911ee 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:ab4e14b911ee 8 * copies of the Software, and to permit persons to whom the Software is
simon 0:ab4e14b911ee 9 * furnished to do so, subject to the following conditions:
simon 0:ab4e14b911ee 10 *
simon 0:ab4e14b911ee 11 * The above copyright notice and this permission notice shall be included in
simon 0:ab4e14b911ee 12 * all copies or substantial portions of the Software.
simon 0:ab4e14b911ee 13 *
simon 0:ab4e14b911ee 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:ab4e14b911ee 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:ab4e14b911ee 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:ab4e14b911ee 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:ab4e14b911ee 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:ab4e14b911ee 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:ab4e14b911ee 20 * THE SOFTWARE.
simon 0:ab4e14b911ee 21 */
simon 0:ab4e14b911ee 22
simon 0:ab4e14b911ee 23 #include "PCF8574.h"
simon 0:ab4e14b911ee 24 #include "mbed.h"
simon 0:ab4e14b911ee 25
jolyon 2:6c22af0aafbb 26 JPCF8574::JPCF8574(PinName sda, PinName scl, int address)
simon 0:ab4e14b911ee 27 : _i2c(sda, scl) {
simon 0:ab4e14b911ee 28 _address = address;
simon 0:ab4e14b911ee 29 }
simon 0:ab4e14b911ee 30
jolyon 2:6c22af0aafbb 31 int JPCF8574::read() {
simon 0:ab4e14b911ee 32 char foo[1];
jolyon 2:6c22af0aafbb 33 char Error = 0;
jolyon 2:6c22af0aafbb 34 Error = _i2c.read(_address, foo, 1);
jolyon 2:6c22af0aafbb 35 if (Error == 1)
jolyon 2:6c22af0aafbb 36 {
jolyon 2:6c22af0aafbb 37 foo[0] = 0;
jolyon 2:6c22af0aafbb 38 }
jolyon 2:6c22af0aafbb 39
simon 0:ab4e14b911ee 40 return foo[0];
simon 0:ab4e14b911ee 41 }
simon 0:ab4e14b911ee 42
jolyon 2:6c22af0aafbb 43 void JPCF8574::write(int data) {
simon 0:ab4e14b911ee 44 char foo[1];
simon 0:ab4e14b911ee 45 foo[0] = data;
simon 1:ec8da0c59403 46 _i2c.write(_address, foo, 1);
simon 0:ab4e14b911ee 47 }
jolyon 2:6c22af0aafbb 48