mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.3.3 PCF8574
This commit is contained in:
parent
146ce589d0
commit
19952ad1ae
@ -2,6 +2,10 @@ compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- leonardo
|
||||
- due
|
||||
- zero
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
@ -4,10 +4,14 @@ name: Arduino CI
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
arduino_ci:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: Arduino-CI/action@master
|
||||
# Arduino-CI/action@v0.1.1
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2021 Rob Tillaart
|
||||
Copyright (c) 2013-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -2,15 +2,17 @@
|
||||
// FILE: PCF8574.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 02-febr-2013
|
||||
// VERSION: 0.3.2
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||
// URL: https://github.com/RobTillaart/PCF8574
|
||||
// http://forum.arduino.cc/index.php?topic=184800
|
||||
//
|
||||
// HISTORY:
|
||||
//
|
||||
// 0.3.3 2021-12-23 update library.json, license, readme, minor edits
|
||||
// 0.3.2 2021-07-04 fix #25 add setAddress()
|
||||
// 0.3.1 2021-04-23 Fix for platformIO compatibility
|
||||
// 0.3.0 2021-01-03 multiWire support - inspirated by mattbue - issue #14
|
||||
// 0.3.0 2021-01-03 multiWire support - inspired by mattbue - issue #14
|
||||
// 0.2.4 2020-12-17 fix #6 tag problem 0.2.3
|
||||
// 0.2.3 2020-12-14 fix #6 readButton8 ambiguity
|
||||
// 0.2.2 2020-12-07 add Arduino-ci + start unit test + _wire->h in PCF8574.h
|
||||
@ -36,7 +38,7 @@
|
||||
// 0.1.05 2016-04-30 refactor, +toggleMask, +rotLeft, +rotRight
|
||||
// 0.1.04 2015-05-09 removed ambiguity in read8()
|
||||
// 0.1.03 2015-03-02 address int -> uint8_t
|
||||
// 0.1.02 replaced ints with uint8_t to reduce footprint;
|
||||
// 0.1.02 replaced integers with uint8_t to reduce footprint;
|
||||
// added default value for shiftLeft() and shiftRight()
|
||||
// renamed status() to lastError();
|
||||
// 0.1.01 added value(); returns last read 8 bit value (cached);
|
||||
@ -59,7 +61,7 @@ PCF8574::PCF8574(const uint8_t deviceAddress, TwoWire *wire)
|
||||
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t val)
|
||||
bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t value)
|
||||
{
|
||||
_wire = &Wire;
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
@ -69,17 +71,17 @@ bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t val)
|
||||
_wire->begin();
|
||||
}
|
||||
if (! isConnected()) return false;
|
||||
PCF8574::write8(val);
|
||||
PCF8574::write8(value);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool PCF8574::begin(uint8_t val)
|
||||
bool PCF8574::begin(uint8_t value)
|
||||
{
|
||||
_wire->begin();
|
||||
if (! isConnected()) return false;
|
||||
PCF8574::write8(val);
|
||||
PCF8574::write8(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -104,11 +106,11 @@ uint8_t PCF8574::getAddress()
|
||||
}
|
||||
|
||||
|
||||
// removed _wire->beginTransmission(addr);
|
||||
// with @100KHz -> 265 micros()
|
||||
// without @100KHz -> 132 micros()
|
||||
// without @400KHz -> 52 micros()
|
||||
// TODO @800KHz -> ??
|
||||
// removed _wire->beginTransmission(_address);
|
||||
// with @100 KHz -> 265 micros()
|
||||
// without @100 KHz -> 132 micros()
|
||||
// without @400 KHz -> 52 micros()
|
||||
// TODO @800 KHz -> ??
|
||||
uint8_t PCF8574::read8()
|
||||
{
|
||||
if (_wire->requestFrom(_address, (uint8_t)1) != 1)
|
||||
@ -252,10 +254,11 @@ uint8_t PCF8574::readButton(const uint8_t pin)
|
||||
|
||||
uint8_t temp = _dataOut;
|
||||
PCF8574::write(pin, HIGH);
|
||||
uint8_t rtn = PCF8574::read(pin);
|
||||
uint8_t value = PCF8574::read(pin);
|
||||
PCF8574::write8(temp);
|
||||
return rtn;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: PCF8574.H
|
||||
// FILE: PCF8574.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 02-febr-2013
|
||||
// VERSION: 0.3.2
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||
// URL: https://github.com/RobTillaart/PCF8574
|
||||
// http://forum.arduino.cc/index.php?topic=184800
|
||||
@ -17,7 +17,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define PCF8574_LIB_VERSION (F("0.3.2"))
|
||||
#define PCF8574_LIB_VERSION (F("0.3.3"))
|
||||
|
||||
#ifndef PCF8574_INITIAL_VALUE
|
||||
#define PCF8574_INITIAL_VALUE 0xFF
|
||||
@ -31,32 +31,38 @@
|
||||
class PCF8574
|
||||
{
|
||||
public:
|
||||
explicit PCF8574(const uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
explicit PCF8574(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire);
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool begin(uint8_t sda, uint8_t scl, uint8_t val = PCF8574_INITIAL_VALUE);
|
||||
bool begin(uint8_t sda, uint8_t scl, uint8_t value = PCF8574_INITIAL_VALUE);
|
||||
#endif
|
||||
bool begin(uint8_t val = PCF8574_INITIAL_VALUE);
|
||||
bool begin(uint8_t value = PCF8574_INITIAL_VALUE);
|
||||
bool isConnected();
|
||||
|
||||
|
||||
// note: setting the address corrupt internal buffer values
|
||||
// a read8() / write8() call updates them.
|
||||
bool setAddress(const uint8_t deviceAddress);
|
||||
uint8_t getAddress();
|
||||
|
||||
|
||||
uint8_t read8();
|
||||
uint8_t read(const uint8_t pin);
|
||||
uint8_t value() const { return _dataIn; };
|
||||
|
||||
|
||||
void write8(const uint8_t value);
|
||||
void write(const uint8_t pin, const uint8_t value);
|
||||
uint8_t valueOut() const { return _dataOut; }
|
||||
|
||||
|
||||
//added 0.1.07/08 Septillion
|
||||
inline uint8_t readButton8() { return PCF8574::readButton8(_buttonMask); }
|
||||
uint8_t readButton8(const uint8_t mask);
|
||||
uint8_t readButton(const uint8_t pin);
|
||||
inline void setButtonMask(const uint8_t mask) { _buttonMask = mask; };
|
||||
uint8_t getButtonMask() { return _buttonMask; };
|
||||
|
||||
|
||||
// rotate, shift, toggle, reverse expect all lines are output
|
||||
void toggle(const uint8_t pin);
|
||||
@ -67,8 +73,10 @@ public:
|
||||
void rotateLeft(const uint8_t n = 1);
|
||||
void reverse();
|
||||
|
||||
|
||||
int lastError();
|
||||
|
||||
|
||||
private:
|
||||
uint8_t _address;
|
||||
uint8_t _dataIn;
|
||||
@ -81,3 +89,4 @@ private:
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/PCF8574/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/PCF8574/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PCF8574/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/PCF8574/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PCF8574/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PCF8574/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PCF8574.svg?maxAge=3600)](https://github.com/RobTillaart/PCF8574/releases)
|
||||
|
||||
|
||||
# PCF8574
|
||||
|
||||
Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||
@ -13,7 +16,7 @@ Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||
Related to the PCF8575 16 channel IO expander library https://github.com/RobTillaart/PCF8575
|
||||
|
||||
This library gives easy control over the 8 pins of a PCF8574 and PCF8574A chip.
|
||||
These chips are identical in behavior although there are two distinct address ranges.
|
||||
These chips are identical in behaviour although there are two distinct address ranges.
|
||||
|
||||
| TYPE | ADDRESS-RANGE | notes |
|
||||
|:---------|:-------------:|:------------------------:|
|
||||
@ -25,25 +28,25 @@ to 16 x 8 = 128 IO lines. To maximize IO lines combine 8 x PCF8575 + 8 x PCF8574
|
||||
128 + 64 = 192 IO lines. Be sure to have a well dimensioned power supply.
|
||||
|
||||
The library allows to read and write both single pins or 8 pins at once.
|
||||
Furthermore some additional functions are implemented that are
|
||||
playful but useful.
|
||||
Furthermore some additional functions are implemented that are playful but useful.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
**PCF8574_INITIAL_VALUE** is a define that can be set compile time or before
|
||||
the include of "pcf8574.h" to overrule the default value used with the
|
||||
**begin()** call.
|
||||
the include of "pcf8574.h" to overrule the default value used with the **begin()** call.
|
||||
|
||||
|
||||
### Constructor
|
||||
|
||||
- **PCF8574(deviceAddress, TwoWire \*wire = &Wire)** Constructor with device address,
|
||||
and optional the Wire interface as parameter.
|
||||
- **bool begin(val = PCF8574_INITIAL_VALUE)** set the initial value for the pins and masks.
|
||||
- **bool begin(sda, scl, val = PCF8574_INITIAL_VALUE)** idem, for the ESP32 where one can choose the I2C pins.
|
||||
- **PCF8574(uint8_t deviceAddress = 0x20, TwoWire \*wire = &Wire)** Constructor with optional device address, default 0x20,
|
||||
and the optional Wire interface as parameter.
|
||||
- **bool begin(uint8_t value = PCF8574_INITIAL_VALUE)** set the initial value for the pins and masks.
|
||||
- **bool begin(uint8_t sda, uint8_t scl, uint8_t value = PCF8574_INITIAL_VALUE)** idem, for the ESP32 where one can choose the I2C pins.
|
||||
- **bool isConnected()** checks if the address set in the constructor or by **setAddress()** is visible on the I2C bus.
|
||||
- **bool setAddress(const uint8_t deviceAddress)** sets the device address after construction. Can be used to switch between PCF8574 modules runtime. Note this corrupts internal buffered values, so one might need to call **read8()** and/or **write8()**. Returns true if address can be found on I2C bus.
|
||||
- **bool setAddress(const uint8_t deviceAddress)** sets the device address after construction.
|
||||
Can be used to switch between PCF8574 modules runtime. Note this corrupts internal buffered values,
|
||||
so one might need to call **read8()** and/or **write8()**. Returns true if address can be found on I2C bus.
|
||||
- **uint8_t getAddress()** returns the device address.
|
||||
|
||||
|
||||
@ -53,17 +56,27 @@ and optional the Wire interface as parameter.
|
||||
- **uint8_t read(uint8_t pin)** reads a single pin; pin = 0..7
|
||||
- **uint8_t value()** returns the last read inputs again, as this information is buffered
|
||||
in the class this is faster than reread the pins.
|
||||
- **void write8(const uint8_t value)** writes all 8 pins at once. This one does the actual reading.
|
||||
- **uint8_t write(const uint8_t pin, const uint8_t value)** writes a single pin; pin = 0..7; value is HIGH(1) or LOW (0)
|
||||
- **void write8(const uint8_t value)** writes all 8 pins at once. This one does the actual writing.
|
||||
- **uint8_t write(const uint8_t pin, const uint8_t value)** writes a single pin; pin = 0..7;
|
||||
value is HIGH(1) or LOW (0)
|
||||
- **valueOut()** returns the last written data.
|
||||
|
||||
|
||||
### Button
|
||||
|
||||
- **void setButtonMask(const uint8_t mask)**
|
||||
- **uint8_t readButton8()**
|
||||
- **uint8_t readButton8(const uint8_t mask)**
|
||||
- **uint8_t readButton(const uint8_t pin)**
|
||||
The **"button"** functions are to be used when you mix input and output on one IC.
|
||||
It does not change / affect the pins used for output by masking these.
|
||||
Typical usage is to call **setButtonMask()** once in setup as pins do not (often) change
|
||||
during program execution.
|
||||
|
||||
- **void setButtonMask(const uint8_t mask)** sets the (bit) mask which lines are input.
|
||||
- **uint8_t getButtonMask()** returns the set buttonMask.
|
||||
- **uint8_t readButton8()** use the mask set by setButtonMask to select specific input pins.
|
||||
- **uint8_t readButton8(const uint8_t mask)** use a specific mask to select specific input pins.
|
||||
Note this can be a subset of the pins set with **setButtonMask()** if one wants to process not all.
|
||||
- **uint8_t readButton(const uint8_t pin)** read a singe input pin.
|
||||
|
||||
Background - https://github.com/RobTillaart/Arduino/issues/38
|
||||
|
||||
|
||||
### Special
|
||||
@ -71,13 +84,13 @@ in the class this is faster than reread the pins.
|
||||
- **void toggle(const uint8_t pin)** toggles a single pin
|
||||
- **void toggleMask(const uint8_t mask = 0xFF)** toggles a selection of pins,
|
||||
if you want to invert all pins use 0xFF (default value).
|
||||
- **void shiftRight(const uint8_t n = 1)** shifts output channels n pins (default 1) pins right (e.g. leds ).
|
||||
- **void shiftRight(const uint8_t n = 1)** shifts output channels n pins (default 1) pins right (e.g. LEDs ).
|
||||
Fills the higher lines with zero's.
|
||||
- **void shiftLeft(const uint8_t n = 1)** shifts output channels n pins (default 1) pins left (e.g. leds ).
|
||||
- **void shiftLeft(const uint8_t n = 1)** shifts output channels n pins (default 1) pins left (e.g. LEDs ).
|
||||
Fills the lower lines with zero's.
|
||||
- **void rotateRight(const uint8_t n = 1)** rotates output channels to right, moving lowest line to highest line.
|
||||
- **void rotateLeft(const uint8_t n = 1)** rotates output channels to left, moving highest line to lowest line.
|
||||
- **void reverse()** revers the "bit pattern" of the lines, high to low and vice versa.
|
||||
- **void reverse()** reverse the "bit pattern" of the lines, swapping pin 7 with 0, 6 with 1, 5 with 2 and 4 with 3.
|
||||
|
||||
|
||||
### Misc
|
||||
@ -97,3 +110,12 @@ Fills the lower lines with zero's.
|
||||
## Operation
|
||||
|
||||
See examples
|
||||
|
||||
It is advised to use pull-up or pull-down resistors so the lines have a defined state at startup.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- update documentation
|
||||
- link to related libraries.
|
||||
|
||||
|
@ -2,15 +2,15 @@
|
||||
// FILE: PCF8574_Wire2.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2016-04-30
|
||||
//
|
||||
// PUPROSE: demo
|
||||
//
|
||||
|
||||
|
||||
#include "PCF8574.h"
|
||||
|
||||
// adjust addresses if needed
|
||||
PCF8574 PCF(0x39, &Wire2);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -34,6 +34,7 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("HLT");
|
||||
@ -46,6 +47,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void doHigh()
|
||||
{
|
||||
PCF.write(4, HIGH);
|
||||
@ -54,6 +56,7 @@ void doHigh()
|
||||
Serial.println(x, HEX);
|
||||
}
|
||||
|
||||
|
||||
void doLow()
|
||||
{
|
||||
PCF.write(4, LOW);
|
||||
@ -62,6 +65,7 @@ void doLow()
|
||||
Serial.println(x, HEX);
|
||||
}
|
||||
|
||||
|
||||
void doToggle()
|
||||
{
|
||||
PCF.toggle(4);
|
||||
@ -72,3 +76,4 @@ void doToggle()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
// DATE: 2020-12-07
|
||||
// PUPROSE: test PCF8574 library
|
||||
//
|
||||
|
||||
// TEST SETUP
|
||||
// Connect INT pin of the PCF8574 to UNO pin 2
|
||||
//
|
||||
@ -12,10 +11,12 @@
|
||||
// Place a pull up resistor 4K7 between pin and 5V
|
||||
// Place a capacitor 10-400pF between pin and GND
|
||||
|
||||
|
||||
#include "PCF8574.h"
|
||||
|
||||
PCF8574 PCF(0x38);
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
//
|
||||
// INTERRUPT ROUTINE + FLAG
|
||||
@ -47,6 +48,7 @@ void setup()
|
||||
attachInterrupt(digitalPinToInterrupt(IRQPIN), pcf_irq, FALLING);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
@ -64,4 +66,6 @@ void loop()
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,15 +2,15 @@
|
||||
// FILE: PCF8574_isConnected.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-01-03
|
||||
//
|
||||
// PUPROSE: demo
|
||||
//
|
||||
// PUPROSE: demo isConnected function
|
||||
|
||||
|
||||
#include "PCF8574.h"
|
||||
|
||||
// adjust addresses if needed
|
||||
PCF8574 PCF_39(0x39);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -32,8 +32,11 @@ void setup()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
// FILE: PCF8574_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-01-24
|
||||
//
|
||||
// PUPROSE: test PCF8574 library
|
||||
// PUPROSE: test PCF8574 library at different I2C speeds.
|
||||
|
||||
|
||||
#include "PCF8574.h"
|
||||
|
||||
@ -11,6 +11,7 @@ PCF8574 PCF(0x38);
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -39,10 +40,13 @@ void setup()
|
||||
Serial.println(stop - start);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,9 +2,8 @@
|
||||
// FILE: PCF8574_rotaryEncoder.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-05-08
|
||||
//
|
||||
// PUPROSE: demo PCF8574 as rotary encoder reader.
|
||||
|
||||
//
|
||||
//
|
||||
// RotaryEncoder PCF8574 UNO
|
||||
// --------------------------------------
|
||||
@ -30,6 +29,8 @@ uint8_t lastpos[4] = {0, 0, 0, 0};
|
||||
int32_t encoder[4] = {0, 0, 0, 0};
|
||||
volatile bool flag = false;
|
||||
|
||||
|
||||
// IRQ routine
|
||||
void moved()
|
||||
{
|
||||
flag = true;
|
||||
@ -50,7 +51,8 @@ void setup()
|
||||
Wire.begin();
|
||||
if (decoder.begin() == false)
|
||||
{
|
||||
Serial.println("\nERROR: cannot communicate to keypad.\nPlease reboot / adjust address.\n");
|
||||
Serial.println("\nERROR: cannot communicate to PCF8574.");
|
||||
Serial.println("Please reboot / adjust address.\n");
|
||||
while (1);
|
||||
}
|
||||
Wire.setClock(600000);
|
||||
@ -129,3 +131,4 @@ void updateRotaryDecoder()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
|
||||
//
|
||||
// FILE: PCF8574_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 7-febr-2013
|
||||
//
|
||||
// PUPROSE: test PCF8574 library
|
||||
//
|
||||
|
||||
|
||||
#include "PCF8574.h"
|
||||
|
||||
PCF8574 PCF_01(0x38);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -26,6 +25,7 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("HLT");
|
||||
@ -38,6 +38,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void doHigh()
|
||||
{
|
||||
PCF_01.write(4, HIGH);
|
||||
@ -46,6 +47,7 @@ void doHigh()
|
||||
Serial.println(x, HEX);
|
||||
}
|
||||
|
||||
|
||||
void doLow()
|
||||
{
|
||||
PCF_01.write(4, LOW);
|
||||
@ -54,6 +56,7 @@ void doLow()
|
||||
Serial.println(x, HEX);
|
||||
}
|
||||
|
||||
|
||||
void doToggle()
|
||||
{
|
||||
PCF_01.toggle(4);
|
||||
@ -61,3 +64,7 @@ void doToggle()
|
||||
Serial.print("Read ");
|
||||
Serial.println(x, HEX);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
//
|
||||
// FILE: pcf8574_test.ino
|
||||
// FILE: PCF8574_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 27-08-2013
|
||||
//
|
||||
// PUPROSE: demo
|
||||
//
|
||||
|
||||
|
||||
#include "PCF8574.h"
|
||||
|
||||
// adjust addresses if needed
|
||||
PCF8574 PCF_38(0x38); // add switches to lines (used as input)
|
||||
PCF8574 PCF_39(0x39); // add leds to lines (used as output)
|
||||
PCF8574 PCF_39(0x39); // add LEDs to lines (used as output)
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -62,12 +62,15 @@ void setup()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// echos the lines
|
||||
// echo the state of the lines on the other PCF
|
||||
uint8_t value = PCF_38.read8();
|
||||
PCF_39.write8(value);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// END OF FILE
|
||||
|
||||
|
@ -2,14 +2,14 @@
|
||||
// FILE: pcf8574_test2.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2016-04-30
|
||||
//
|
||||
// PUPROSE: demo rotateLeft, -Right and toggleMask
|
||||
//
|
||||
|
||||
|
||||
#include "PCF8574.h"
|
||||
|
||||
// adjust addresses if needed
|
||||
PCF8574 PCF_39(0x39); // add leds to lines (used as output)
|
||||
PCF8574 PCF_39(0x39); // add LEDs to lines (used as output)
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -61,8 +61,11 @@ void setup()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -24,9 +24,11 @@
|
||||
* no matter the set output state when you press the button.
|
||||
*/
|
||||
|
||||
|
||||
#include <PCF8574.h>
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
PCF8574 pcf20(0x20);
|
||||
|
||||
const byte onboardLed = 13;
|
||||
@ -35,6 +37,7 @@ const byte PcfButtonLedPin = 0;
|
||||
unsigned int blinkMillis;
|
||||
unsigned int buttonMillis;
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pcf20.begin();
|
||||
@ -42,6 +45,7 @@ void setup() {
|
||||
pinMode(onboardLed, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
static bool state;
|
||||
unsigned int currentMillis = millis();
|
||||
@ -71,3 +75,7 @@ void loop() {
|
||||
Serial.println(pcf20.read8(), BIN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -24,9 +24,11 @@
|
||||
* no matter the set output state when you press the button.
|
||||
*/
|
||||
|
||||
|
||||
#include <PCF8574.h>
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
PCF8574 pcf20(0x20);
|
||||
|
||||
const byte onboardLed = 13;
|
||||
@ -36,50 +38,52 @@ const byte PcfLedPin = 1;
|
||||
unsigned int blinkMillis;
|
||||
unsigned int buttonMillis;
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pcf20.begin();
|
||||
|
||||
pinMode(onboardLed, OUTPUT);
|
||||
|
||||
//As alternative to adding the mask to buttonRead8() every time
|
||||
//you can set it once.
|
||||
//Without setting a mask buttonRead8() will effect ALL pins.
|
||||
//Not a problem when using things like LEDs.
|
||||
//pcf20.setButtonMask(_BV(PcfButtonLedPin));
|
||||
// As alternative to adding the mask to buttonRead8() every time
|
||||
// you can set it once.
|
||||
// Without setting a mask buttonRead8() will effect ALL pins.
|
||||
// Not a problem when using things like LEDs.
|
||||
// pcf20.setButtonMask(_BV(PcfButtonLedPin));
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
static bool state;
|
||||
unsigned int currentMillis = millis();
|
||||
|
||||
//Limit button read to 20 times a second
|
||||
//Fast enough for most buttons
|
||||
//but this way you don't have a dimmer output because it's blanked during button read
|
||||
//a read takes 460us t 16Mhz Arduino and normal I2C speed.
|
||||
// Limit button read to 20 times a second
|
||||
// Fast enough for most buttons
|
||||
// but this way you don't have a dimmer output because it's blanked during button read
|
||||
// a read takes 460us t 16Mhz Arduino and normal I2C speed.
|
||||
if(currentMillis - buttonMillis >= 50){
|
||||
buttonMillis = currentMillis;
|
||||
|
||||
//read all states but only force PcfButtonLedPin HIGH during the
|
||||
//buttonRead8()
|
||||
//Alternativly the mask could have been set with setButtonMask().
|
||||
//Then the mask can be omitted here. See setup()
|
||||
// read all states but only force PcfButtonLedPin HIGH during the
|
||||
// buttonRead8()
|
||||
// Alternatively the mask could have been set with setButtonMask().
|
||||
// Then the mask can be omitted here. See setup()
|
||||
// byte inputStates = pcf20.readButton8(_BV(PcfButtonLedPin));
|
||||
byte inputStates = pcf20.readButton8(1 << PcfButtonLedPin); // Keep Arduino-CI happy
|
||||
|
||||
//check the bit of PcfButtonLedPin
|
||||
// check the bit of PcfButtonLedPin
|
||||
if(state != bitRead(inputStates, PcfButtonLedPin)){
|
||||
if(state){
|
||||
//toggle the LED
|
||||
// toggle the LED
|
||||
digitalWrite(onboardLed, !digitalRead(onboardLed));
|
||||
}
|
||||
state = !state;
|
||||
}
|
||||
}
|
||||
|
||||
//Lets blink the same output
|
||||
// Lets blink the same output
|
||||
if(currentMillis - blinkMillis >= 500){
|
||||
//Update time
|
||||
// Update time
|
||||
blinkMillis = currentMillis;
|
||||
|
||||
pcf20.toggle(PcfButtonLedPin);
|
||||
@ -87,3 +91,7 @@ void loop() {
|
||||
Serial.println(pcf20.read8(), BIN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -38,3 +38,4 @@ PCF8574_LIB_VERSION LITERAL1
|
||||
PCF8574_OK LITERAL1
|
||||
PCF8574_PIN_ERROR LITERAL1
|
||||
PCF8574_I2C_ERROR LITERAL1
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/PCF8574.git"
|
||||
},
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "PCF8574.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=PCF8574
|
||||
version=0.3.2
|
||||
version=0.3.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||
|
@ -42,16 +42,17 @@ PCF8574 PCF(0x38);
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "PCF8574_LIB_VERSION: %s\n", (char *) PCF8574_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_begin)
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", PCF8574_LIB_VERSION);
|
||||
|
||||
PCF8574 PCF(0x38);
|
||||
|
||||
PCF.begin();
|
||||
@ -103,4 +104,5 @@ unittest(test_address)
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// --------
|
||||
|
Loading…
Reference in New Issue
Block a user