Giter Club home page Giter Club logo

keypad's Introduction

Keypad

A small library to interact with keypads connected to GPIO pins.

Its really just a defined behavior macro to make setting up a keypad very easy to get up a running. In theory, this can be used on any platform with GPIO pins, but is mainly developed with the raspberry pi in mind.

It can be used with membrane or mechanical keypads, such as these:

If you want to know more about how it works, I found this article to be very helpful. In short, keypads are split into rows and columns and work by changing the pin state HIGH/LOW on keypress. You then traverse your known pins and match it to a predefined matrix of characters to determine which button is actually being pressed.

โš ๏ธ keypad sets the internal pull-up resistors on raspberry pi so you can plug every pin of the keypad directly into the board. However, that is currently hardware dependent and not supported for other boards. For those, see the setup for determining your pinout and setup.

Installation

Add keypad to your list of dependencies in mix.exs:

def deps do
  [
    {:keypad, "~> 0.3"}
  ]
end

Example

keypad is a small GenServer to handle receiving messages from GPIO pins via Circuits.GPIO and then reacting to them. keypad only implements the logic of reacting to pin state change and finding which character it correlates to. It does not host any logic what to do with that value and expects a handle_keypress/1 function to be implemented to receive the deduced key presses.

It comes with some common predefined matricies of characters so assuming you are using the default row and column GPIO pins, you can make a simple module like so:

defmodule MyModule do
  use Keypad, size: :four_by_four

  @impl true
  def handle_keypress(key, _), do: IO.inspect(key, label: "KEYPRESS: )
end

Then in an iex session, start your keypad procss and start pressing buttons

$ MyModule.start_link

# Press some buttons
KEYPRESS: 1
KEYPRESS: 5
...

For more complex configuration and examples, see the configuration doc.

keypad's People

Contributors

chrisben avatar jjcarstens 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.