Git Product home page Git Product logo

smart-button's Introduction

Smart Button

A simple GPIO-controlled button for the Raspberry Pi.

Prerequisites

  • Python version 3
  • RPi.GPIO (at least version 0.5.2)

Usage

Unfortunately, you will have to run the smart-button.py with super-user privileges, i.e. invoke sude ./smart-button.py.

smart-button.py [-q] [-P port] [-t timeout] [-d debounce] [-l action] [-c action]

    -q          quiet: suppress diagnostic output
    -P port     act on button connected to specified BCM port (default: 21)
    -t timeout  timeout value for long press (default: 5.0)
    -d debounce time (default: 0.15)
    -l action   the action to be run on long press
    -c action   the action to be run on normal press

Examples

smart-button.py -P 16 -c 'curl -X POST https://maker.ifttt.com/trigger/button/with/key/$YOUR_KEY'

This example connects the button on BCM port 16 to the given command. As a result, pressing the button triggers the given IFTTT action.

smart-button.py -t 3.2 -c 'echo "short press"' -l 'echo "long press"'

Prints the string „short press“ if the button is pressed quickly, or the string „long press“ when the button is held down for at least 3.2 seconds.

Using as a System Service

In combination with a systemd service, you could create a shutdown button for your Raspi as follows:

  1. Copy the file shutdown.service into your platform's systemd home, e.g./etc/systemd/system on Debian.
  2. Copy the file smart-button.py into /usr/local/bin (or wherever you want it to be.)
  3. Start shutdown.service: sudo systemctl start shutdown.service.

The file shutdown.service could have the following contents:

[Unit]
Description=Shutdown button

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/smart-button.py -q -l 'shutdown -h now'
StandardOutput=syslog

[Install]
WantedBy=multi-user.target

License

This software is licensed under the MIT License (MIT), see LICENSE.

smart-button's People

Contributors

obgm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

smart-button's Issues

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.