-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db8bf3a
commit b87dcd9
Showing
5 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Arduino Button Library | ||
// https://github.com/JChristensen/JC_Button | ||
// Copyright (C) 2018 by Jack Christensen and licensed under | ||
// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html | ||
// | ||
// Example sketch to demonstrate toggle buttons. | ||
|
||
#include <JC_Button.h> // https://github.com/JChristensen/JC_Button | ||
|
||
// pin assignments | ||
const byte | ||
LED1_PIN(5), // connect an LED to ground, through an appropriate current limiting resistor | ||
LED2_PIN(6), // connect an LED to ground, through an appropriate current limiting resistor | ||
BUTTON1_PIN(7), // connect a button switch from this pin to ground | ||
BUTTON2_PIN(8); // connect a button switch from this pin to ground | ||
|
||
ToggleButton // define the buttons | ||
btn1(BUTTON1_PIN), // this button's initial state is off | ||
btn2(BUTTON2_PIN, true); // this button's initial state is on | ||
|
||
void setup() | ||
{ | ||
// initialize the button objects | ||
btn1.begin(); | ||
btn2.begin(); | ||
|
||
// set the LED pins as outputs | ||
pinMode(LED1_PIN, OUTPUT); | ||
pinMode(LED2_PIN, OUTPUT); | ||
|
||
// show the initial states | ||
digitalWrite(LED1_PIN, btn1.toggleState()); | ||
digitalWrite(LED2_PIN, btn2.toggleState()); | ||
} | ||
|
||
void loop() | ||
{ | ||
// read the buttons | ||
btn1.read(); | ||
btn2.read(); | ||
|
||
// if button state changed, update the LEDs | ||
if (btn1.changed()) digitalWrite(LED1_PIN, btn1.toggleState()); | ||
if (btn2.changed()) digitalWrite(LED2_PIN, btn2.toggleState()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=JC_Button | ||
version=2.0.1 | ||
version=2.1.0 | ||
author=Jack Christensen <[email protected]> | ||
maintainer=Jack Christensen <[email protected]> | ||
sentence=Arduino library to debounce button switches, detect presses, releases, and long presses. | ||
paragraph=The Button library is for debouncing and reading momentary contact switches like tactile button switches. "Long presses" of arbitrary length can be detected. Works well in state machine constructs. Use the read() function to read each button in the main loop, which should execute as fast as possible. | ||
paragraph=Copyright (C) 2018-2019 by Jack Christensen and licensed under GNU GPL v3.0. | ||
category=Signal Input/Output | ||
url=https://github.com/JChristensen/JC_Button | ||
architectures=avr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters