Giter Club home page Giter Club logo

arduinoshiftin's Introduction

ArduinoShiftIn

This is a small library for reading in values from a 74HC165 8 bit shift register.

The Arduino has only a limited amount of pins, therefore it might happen that you run out of pins. For this case, the 74HC165 comes to the rescue. It is an 8 bit shift register. It allows you to read in 8 values by only using 4 pins on your Arduino. Furthermore you can daisy-chain several shift registers by still only using 4 Arduino Pins.

Easy install (zip import)

The easiest way to install this library is by downloading the newest release and then importing it. You don't have to unzip it. Just open your Arduino IDE and navigate to Sketch > Include Library > Add .ZIP and then select the zip file.

Manual install

Of course you can also install this library manually. To do so, download the newest release and unzip it. Then you have to copy the ShiftIn folder (NOT the ShiftIn-x.y.z folder) and copy it to your Arduino library folder:

  • Windows: My Documents\Arduino\libraries\
  • Mac and Linux: Documents/Arduino/libraries/

After that you just have to restart your Arduino IDE.

Usage

If you have installed this library, you can include it by navigating to Sketch > Include Library > ShiftIn. This will add the line #include <ShiftIn.h> to your sketch (of course you could also write this line manually).

Now you can actually use this library:

// Init ShiftIn instance with one chip.
#define SHIFT_REGISTER_CHIP_COUNT 1
#include <ShiftIn.h>

// declare pins: ploadPin, clockPin, dataPin, clockEnablePin
ShiftIn shift(8,12,11,9);

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  shift.read();

  for (int n = 0; n < 8; ++n)
  {
    // Show state of each buttons
    if (shift.state(n))
    {
      Serial.print("1");
    }
    else
    {
      Serial.print("0");
    }
  }

  Serial.println("");
  delay(1000);
}

Breadboard layout for one shift register

If you want to use two shift registers, you only have to change the declaration from #define SHIFT_REGISTER_CHIP_COUNT 1 to #define SHIFT_REGISTER_CHIP_COUNT 2. The layout can look like this; Breadboard layout for two shift registers

Gets/sets the delay time for the clock pin (in microseconds). This value defaults to 5 and in most cases there's no need to change it.

uint8_t getPulseWidth()
void setPulseWidth(uint8_t value)

Returns true if button i has changed its state during the last frame.

boolean hasChanged(int i)

Returns the state of a single button for this frame / last frame

boolean state(int i)
boolean last(int i)

Whether button i is just pressed/released

boolean pressed(int id) // wasn't pressed lasst frame, but is pressed now
boolean released(int id) // was pressed last frame, but is released now

This function (or the update function) should be called each frame exactly once. It will read in all values from the shift registers.

void read()

arduinoshiftin's People

Contributors

infectedbytes avatar

Forkers

ivelichkevich

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.