GithubHelp home page GithubHelp logo

00mjk / pca9534 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alotaiba/pca9534

0.0 0.0 0.0 158 KB

PCA9534 I/O expander library with for Particle for easy interfacing with PCA9534 chip.

License: MIT License

C++ 100.00%

pca9534's Introduction

PCA9534 I/O Expander

PCA9534 GPIO expander library for Particle devices with Particle like API calls. It makes working with PCA9534 I/O expander pins easier, with familiar functions like pinMode() and digitalWrite(). Refer to the datasheet for more information about the chip.

Usage

Hardware connection

Connect an LED to PCA9534 pin 0 chip, add the PCA9534 library to your project and follow this simple example:

#include "PCA9534.h"

#define GPIO_PIN_LED 0

PCA9534 gpio;

void setup() {
  gpio.begin();
  gpio.pinMode(GPIO_PIN_LED, OUTPUT);
}

void loop() {
  gpio.digitalWrite(GPIO_PIN_LED, LOW); // LED On
  delay(500);
  gpio.digitalWrite(GPIO_PIN_LED, HIGH); // LED Off
  delay(500);
}

See the examples folder for more details.

Documentation

PCA9534

Creates a new PCA9534 class to manage a PCA9534 chip.

#include "PCA9534.h"
...
...
PCA9534 gpio;
...
...
void setup() {
  gpio.begin();
}

begin([i2caddr])

Initializes the device and performs initial I2C setup. This method should be called before any others are used.

Parameters:

Name Type Description
i2caddr uint8_t Sets the slave address of the PCA9534, defaults to 0x20.
void setup() {
  gpio.begin(0x20);
}

pinMode(pin, mode)

Configures the specified pin to behave either as an input, inverted input, or output.

Parameters:

Name Type Description
pin uint8_t Pin number whose mode you wish to set.
mode uint8_t Pin mode one of: INPUT, INPUT_INVERTED, or OUTPUT.
void setup() {
  gpio.begin();
  gpio.pinMode(0, OUTPUT);
}

digitalWrite(pin, value)

Writes a HIGH or a LOW value to a digital pin.

Parameters:

Name Type Description
pin uint8_t Pin number whose value you wish to set.
value uint8_t Pin value one of: HIGH, or LOW.
void loop() {
  gpio.digitalWrite(0, LOW);
  delay(500);
  gpio.digitalWrite(0, HIGH);
  delay(500);
}

digitalRead(pin)

Reads the value from a specified digital pin, either HIGH or LOW.

Note: when using INPUT_INVERTED on pinMode(), you will get the inverted status.

Parameters:

Name Type Description
pin uint8_t Pin number whose value you wish to get.

Returns:

uint8_t - The status of the pin either HIGH or LOW.

void loop() {
  uint8_t buttonStatus = gpio.digitalRead(1);
  if (buttonStatus == HIGH) {
    gpio.digitalWrite(0, LOW); // LED On
  } else {
    gpio.digitalWrite(0, HIGH); // LED Off
  }
}

LICENSE

Copyright 2017 Abdulrahman Saleh Khamis

Licensed under the MIT license

pca9534's People

Contributors

alotaiba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.