Skip to content

Commit 451480a

Browse files
committed
1.1.4
1 parent 550d2b3 commit 451480a

File tree

10 files changed

+81
-35
lines changed

10 files changed

+81
-35
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
# Flicker
2-
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3-
FLICKER - A library for making capacitive touch easy to use.
1+
# Flicker 1.1.4
2+
### A library for making capacitive touch easy to use.
3+
###### - by Josh Nishikawa <github.com/joshnishikawa/Flicker>
4+
###### The "TouchSwitch" class was adapted from the Bounce library by: Thomas O Fredericks, Eric Lowry, Jim Schimpf and Tom Harkaway
5+
46
Includes all the functions found in the Bounce library, smoothes eratic values to make variable input more useful and includes functions for measuring velocity.
5-
- by Josh Nishikawa (github.com/joshnishikawa/Flicker)
6-
- The "TouchSwitch" class was adapted from the Bounce library by:
7-
Thomas O Fredericks, Eric Lowry, Jim Schimpf and Tom Harkaway
8-
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9-
VERSION LOG
7+
___
8+
### VERSION LOG:
9+
10+
1.1.4
11+
- Added previousDuration() function that can be used on rising/falling edge to return the length of the input's previous state.
12+
- Added rose() and fell(). risingEdge() and fallingEdge() still work.
13+
- Now using bool data type where appropriate.
1014

11-
1.0.4 (current)
15+
1.0.4
1216
- created a library.properties file
1317
- made the version number semver compliant (1.0.4 is the first official release)
1418
- moved source files into src/
@@ -27,7 +31,7 @@ VERSION LOG
2731
- Added the TouchVariable class for stable reading of ranges of input.
2832
- Added the TouchVelocity class for detecting velocity of changes in input.
2933
- Started keeping this version log.
30-
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
34+
___
3135
This program is free software; you can redistribute it and/or modify
3236
it under the terms of the GNU General Public License as published by
3337
the Free Software Foundation; either version 2 of the License, or

examples/on-off_stable/on-off_stable.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// If you hold your finger on the input,
44
// something will happen.
55

6-
const uint8_t touchPin = 17; // CHOOSE A TOUCH PIN
6+
const uint8_t touchPin = 0; // CHOOSE A TOUCH PIN
77
const uint8_t ledPin = 13;
88
TouchSwitch myInput(touchPin);
99

@@ -19,11 +19,13 @@ void setup() {
1919

2020
void loop() {
2121
myInput.update();
22-
if (myInput.risingEdge()){
23-
Serial.println("rose");
22+
23+
if (myInput.rose()){
24+
Serial.print("rose");
2425
}
25-
if (myInput.fallingEdge()){
26+
if (myInput.fell()){
2627
Serial.println("fell");
2728
}
29+
2830
digitalWrite(ledPin, myInput.read());
2931
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <Flicker.h>
2+
3+
// This will tell you how long the input stayed in its PREVIOUS state.
4+
// It may be useful to call this within rose() or fell().
5+
6+
const uint8_t touchPin = 15; // CHOOSE A TOUCH PIN
7+
const uint8_t ledPin = 13;
8+
TouchSwitch myInput(touchPin);
9+
10+
void setup() {
11+
pinMode(ledPin, OUTPUT);
12+
13+
// WARNING! if you setThreshold with no argument,
14+
// the threshold is calculated based on a call to
15+
// touchRead() so DON'T touch the input during setup()
16+
myInput.setThreshold();
17+
}
18+
19+
void loop() {
20+
myInput.update();
21+
22+
if (myInput.fell()){
23+
// After the input was released, print how long it was held.
24+
Serial.println( myInput.previousDuration() );
25+
}
26+
27+
digitalWrite(ledPin, myInput.read());
28+
}

examples/velocity_MIDI/velocity_MIDI.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void loop(){
2121
if (velocity >= 1){
2222
usbMIDI.sendNoteOn(noteNumber, velocity, 0);
2323
}
24-
if (myInput.fallingEdge()){
24+
if (myInput.fell()){
2525
usbMIDI.sendNoteOff(noteNumber, 0, 0);
2626
}
2727
}

examples/velocity_basic/velocity_basic.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ void setup() {
2121

2222
void loop(){
2323
int velocity = myInput.read();
24-
if (myInput.fallingEdge()){
24+
if (myInput.fell()){
2525
digitalWrite(LED, HIGH);
2626
}
27-
if (myInput.risingEdge()){
27+
if (myInput.rose()){
2828
digitalWrite(LED, LOW);
2929
}
3030
if (velocity >= 1){

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Flicker
2-
version=1.0.4
2+
version=1.1.4
33
author=Josh Nishikawa <joshnishikawa@gmail.com>
44
maintainer=Josh Nishikawa <joshnishikawa@gmail.com>
55
sentence=A library for making capacitive touch easy to use.

src/TouchSwitch.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ int TouchSwitch::read(){
6262
}
6363

6464

65-
byte TouchSwitch::risingEdge() {return stateChanged && state; }
65+
byte TouchSwitch::rose() {return stateChanged && state; }
6666

67-
byte TouchSwitch::fallingEdge() {return stateChanged && !state; }
67+
byte TouchSwitch::fell() {return stateChanged && !state; }
6868

6969

7070
unsigned long TouchSwitch::duration(){
@@ -82,17 +82,23 @@ void TouchSwitch::interval(unsigned long interval_millis){
8282
retrigger_millis = 0;
8383
}
8484

85+
unsigned long TouchSwitch::previousDuration()
86+
{
87+
return durationOfPreviousState;
88+
}
8589

8690
// Protected: triggers the pin
8791
int TouchSwitch::trigger(){
8892
int newValue = touchRead(pin);
93+
int current_millis = millis();
8994

9095
if(latched){ // LATCH behavior
9196
if (newValue >= onThreshold){
9297
if (waiting && held_millis >= interval_millis){
9398
state = !state;
9499
waiting = false;
95-
previous_millis = millis();
100+
durationOfPreviousState = current_millis - previous_millis;
101+
previous_millis = current_millis;
96102
return 1;
97103
}
98104
else{return 0;}
@@ -112,7 +118,8 @@ int TouchSwitch::trigger(){
112118
if (waiting && held_millis >= interval_millis){
113119
if (!state){
114120
state = true;
115-
previous_millis = millis();
121+
durationOfPreviousState = current_millis - previous_millis;
122+
previous_millis = current_millis;
116123
return 1;
117124
}
118125
else{
@@ -132,7 +139,8 @@ int TouchSwitch::trigger(){
132139
if(waiting && held_millis >= interval_millis){
133140
if (state){
134141
state = false;
135-
previous_millis = millis();
142+
durationOfPreviousState = current_millis - previous_millis;
143+
previous_millis = current_millis;
136144
return 1;
137145
}
138146
else{
@@ -145,8 +153,7 @@ int TouchSwitch::trigger(){
145153
waiting = true;
146154
return 0;
147155
}
148-
else{return 0;
149-
}
156+
else{return 0;}
150157
}
151158
}
152159
else{

src/TouchSwitch.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ class TouchSwitch{
3838
// Returns the updated pin state.
3939
int read();
4040

41-
// risingEdge() is true for 1 scan after input goes above the threshold.
42-
byte risingEdge();
41+
// rose() is true for 1 scan after input goes above the threshold.
42+
byte rose();
43+
byte risingEdge(){return rose();}
4344

44-
// fallingEdge() is true for 1 scan after input goes below the threshold.
45-
byte fallingEdge();
45+
// fell() is true for 1 scan after input goes below the threshold.
46+
byte fell();
47+
byte fallingEdge(){return fell();}
4648

4749
// Returns the number of milliseconds the pin has been in the current state.
4850
unsigned long duration();
@@ -55,6 +57,8 @@ class TouchSwitch{
5557
// A 'debounce' interval isn't really needed but, if you want one...
5658
void interval(unsigned long interval_millis);
5759

60+
unsigned long previousDuration();
61+
5862
protected:
5963
int trigger();
6064
byte state = 0;
@@ -64,10 +68,11 @@ class TouchSwitch{
6468
unsigned long previous_millis = 0;
6569
unsigned long interval_millis = 0;
6670
unsigned long retrigger_millis = 0;
71+
unsigned long durationOfPreviousState;
6772
byte pin = 0;
68-
byte latched = false;
69-
byte waiting = false;
70-
byte stateChanged = false;
73+
bool latched = false;
74+
bool waiting = false;
75+
bool stateChanged = false;
7176
};
7277

7378
#endif

src/TouchVariable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class TouchVariable{
4444

4545
protected:
4646
byte pin = 0;
47-
byte mapped = false; // true maps input to a predetermined output range
48-
byte adjustInHi = true;//false if using setInputRange(int inLo, int inHi)
47+
bool mapped = false; // true maps input to a predetermined output range
48+
bool adjustInHi = true;//false if using setInputRange(int inLo, int inHi)
4949

5050
int buffer = 0; /* Think of this variable as a container like a capacitor
5151
acting as a low-pass filter. */

src/TouchVelocity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TouchVelocity{
6060

6161
protected:
6262
byte pin;
63-
byte stateChanged;
63+
bool stateChanged;
6464
int inHi, state, peak;
6565
int outLo = 1;
6666
int outHi = 127;

0 commit comments

Comments
 (0)