Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PCF8574.cpp@3:47c298d4a41b, 2022-01-31 (annotated)
- Committer:
- JohnnyK
- Date:
- Mon Jan 31 18:26:50 2022 +0000
- Revision:
- 3:47c298d4a41b
- Parent:
- 2:e076d7b30aea
- Child:
- 4:f93baeb6119c
Added Namespace IO for compatibility with TextLCD library
Who changed what in which revision?
User | Revision | Line number | New 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 |
JohnnyK | 2:e076d7b30aea | 3 | * 2022, 001: JohnnyK, Reworked Constructor to I2C object instead of I2C pins. I can be usefull with anoter I2C slave on same bus |
JohnnyK | 3:47c298d4a41b | 4 | * 2022, 002: JohnnyK, Added Namespace IO for compatibility with TextLCD library |
simon | 0:ab4e14b911ee | 5 | * |
simon | 0:ab4e14b911ee | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 0:ab4e14b911ee | 7 | * of this software and associated documentation files (the "Software"), to deal |
simon | 0:ab4e14b911ee | 8 | * in the Software without restriction, including without limitation the rights |
simon | 0:ab4e14b911ee | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 0:ab4e14b911ee | 10 | * copies of the Software, and to permit persons to whom the Software is |
simon | 0:ab4e14b911ee | 11 | * furnished to do so, subject to the following conditions: |
simon | 0:ab4e14b911ee | 12 | * |
simon | 0:ab4e14b911ee | 13 | * The above copyright notice and this permission notice shall be included in |
simon | 0:ab4e14b911ee | 14 | * all copies or substantial portions of the Software. |
simon | 0:ab4e14b911ee | 15 | * |
simon | 0:ab4e14b911ee | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 0:ab4e14b911ee | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 0:ab4e14b911ee | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 0:ab4e14b911ee | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 0:ab4e14b911ee | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 0:ab4e14b911ee | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 0:ab4e14b911ee | 22 | * THE SOFTWARE. |
simon | 0:ab4e14b911ee | 23 | */ |
simon | 0:ab4e14b911ee | 24 | |
simon | 0:ab4e14b911ee | 25 | #include "PCF8574.h" |
simon | 0:ab4e14b911ee | 26 | #include "mbed.h" |
simon | 0:ab4e14b911ee | 27 | |
JohnnyK | 3:47c298d4a41b | 28 | IO::PCF8574::PCF8574(I2C *i2c, int address) |
JohnnyK | 2:e076d7b30aea | 29 | : _i2c(i2c) { |
simon | 0:ab4e14b911ee | 30 | _address = address; |
simon | 0:ab4e14b911ee | 31 | } |
simon | 0:ab4e14b911ee | 32 | |
JohnnyK | 3:47c298d4a41b | 33 | int IO::PCF8574::read() { |
simon | 0:ab4e14b911ee | 34 | char foo[1]; |
JohnnyK | 2:e076d7b30aea | 35 | _i2c->read(_address, foo, 1); |
simon | 0:ab4e14b911ee | 36 | return foo[0]; |
simon | 0:ab4e14b911ee | 37 | } |
simon | 0:ab4e14b911ee | 38 | |
JohnnyK | 3:47c298d4a41b | 39 | void IO::PCF8574::write(int data) { |
simon | 0:ab4e14b911ee | 40 | char foo[1]; |
simon | 0:ab4e14b911ee | 41 | foo[0] = data; |
JohnnyK | 2:e076d7b30aea | 42 | _i2c->write(_address, foo, 1); |
simon | 0:ab4e14b911ee | 43 | } |