When i varify this code clickButton.ccp i get that im missing a type
clickButton.cpp:3:1: error: ‘ClickButton’ does not name a type
ClickButton::ClickButton(uint8_t buttonPin)
clickButton.cpp:20:1: error: ‘ClickButton’ does not name a type
ClickButton::ClickButton(uint8_t buttonPin, boolean activeType)
clickButton.cpp:36:1: error: ‘ClickButton’ does not name a type
ClickButton::ClickButton(uint8_t buttonPin, boolean activeType, boolean internalPullup)
I have not changed anything in the main clickButton.ccp.
What type do i need to put here?
Hello, sorry should have included that information.
Im using the Particle webide and a Photon.
I created a new clickButton.h file and copy pasted the .h code in to it,
then i also copy pasted the .cpp code in to the clickButton.cpp file.
I guess i need to make use of the #include command?
When i hit varify code i get that message.
I tried to include the clickButton.h to the .cpp file then i get other errors
In file included from clickButton.cpp:2:0:
clickButton.h:8:25: error: expected ')' before 'buttonPin'
ClickButton(uint8_t buttonPin);
Note that im under process of learning so im not an advanced user
Why do you not import the library via the import button?
Do you need to change the library’s behaviour? If not, use the intended workflow.
If you have a look at the demo, you’ll see how to use the lib.
Usually when you add a set of .h/.cpp files via the (+) button top right in Build, you’ll get a corresponding #include line inside your main .ino file.
I am using CoolTerm to check for my serial.print.
I have notice that when i press the button sometimes my prints comes 1 and a half time, and sometimes just some of my print comes.
Here is how it looks when i pushed 5 times.
Reset button was pressed, all values are set to default
Reset button was pressed, all values are set to default
Reset button was pressed, all values are set to default
Reset button was pressed, all values are set to default
Reset button was pressed, all values are set to default
Reset b
As you see the last line should not be there.
Im not sure how to make sure this do not happen?
Is it the delay i need to change or the debounce timer, i have tried many different values but in vain.
Not sure how to continue troubleshoot, can anyone help? Here is my code.
// This #include statement was automatically added by the Particle IDE.
#include "clickButton/clickButton.h"
//---- Declare variables -----------------------------------------------
const int pinResetButton = D1; //the pin where we connect the reset button
const int pinGreenLed = D6; //the pin where we connect the Green led
const int pinYellowLed = D7; //the pin where we connect the Yellow led
//------------------------------------------------------------------------
//---- Here i declare the state check for the inputs --------------------
ClickButton stateResetButton(pinResetButton, HIGH);
//-----------------------------------------------------------------------
//---- Here we declare the counter for the inputs ----
int resetFunction = 0;
//---- Herer i declare the function i will use ---------------------------
void PressResetButton();
//-----------------------------------------------------------------------
void setup() {
//---- We declare respective digital point as outputs and inputs here ----
pinMode(pinResetButton, INPUT_PULLDOWN); // Its an input since it waits for a button to be pressed
pinMode(pinGreenLed, OUTPUT); // Its an output since it need to send a voltage Green led
pinMode(pinYellowLed, OUTPUT); // Its an output since it need to send a voltage to Yellow led
//----------------------------------------------------------------------
//---- We declare the state of each variable when the units gets powered on ----
digitalWrite(pinGreenLed, HIGH); // The GreenLed should always be on if water is good, if water is going bad This one will be LOW
//----------------------------------------------------------------------
//---- For troubleshooting ---------------------------------------------
Serial.begin(9600); // Open a serial port
//----------------------------------------------------------------------
//---- Here is some criterias for the inputs ----
// Setup button timers (all in milliseconds / ms)
// (These are default if not set, but changeable for convenience)
stateResetButton.debounceTime = 10; // Debounce timer in ms
stateResetButton.multiclickTime = 250; // Time limit for multi clicks
stateResetButton.longClickTime = 1000; // time until "held-down clicks" register
//----------------------------------------------------------------------
}
void loop() {
//---- Here we update the status of all Input pin -----
stateResetButton.Update();
//----------------------------------------------------
//---- Here we tell the controller what to do if the status of the inputs meet certain criterias ----
if(stateResetButton.clicks != 0) resetFunction = stateResetButton.clicks;
if(stateResetButton.clicks == 1) PressResetButton();
if(resetFunction == 2) PressResetButton();
if(resetFunction == 3) PressResetButton();
if(resetFunction == -1) PressResetButton();
if(resetFunction == -2) PressResetButton();
if(resetFunction == -3) PressResetButton();
//-----------------------------------------------------
//---- Reset function as this one controlls how many clicks we used ----
resetFunction = 0;
delay(5);
//----------------------------------------------------------------------
}
void PressResetButton(){ // This function is called when reset button is pressed
digitalWrite(pinGreenLed, HIGH); // Turn on green led
digitalWrite(pinYellowLed, LOW); // Turn off yellow led
Serial.println("Reset button was pressed, all values are set to default");
}
I noticed that the LED turns on just fine, its only the text that gets updated wierd in CoolTerm.
I cant say if this is that the Photon is sending the text faulty or if coolterm recive it wierd.
I haven’t looked at your code yet, but the output suggests a possible reason for the broken line.
One full line plus the partial next line look as if you are hitting the 64byte limit of the output buffer.
But the underlying problem is most likely that you are printing too quickly (e.g. debounce or delay might help).
I dont think its delay or debounce, i have tried with so many different values now and always same result.
I noticed one thing.
When i flash decive and first time i press the button, nothing happens.
second time i press the button it sends the serial.print 2 times.
I guess it has something to do with that the variable “function” is empty the first time?
But it do seems that this cause issues with upcoming press on the button.
This is what is seen when i pressed 2 times after a flash on the photon.
All values are set to default
All v
When i click a third time i see this
All values are set to default
All values are set to default // it populated the rest of the sentence on third press?
Fourth press
All values are set to default
All values are set to default
All values are set to default
All values are set to d
It makes sense that it might hit the 64 bit limit but how come it dont write all the text always, why does it save some text for the other press of button. its the same eventhou i put a delay in the end.
Not that it would account for your issue, but I’d avoid all these ifs and do it this way
switch(stateResetButton.clicks)
{
case 0:
// do nothing for 0
break;
//case x:
// do whatever for x
// break;
default: // all non explicitly dealt cases
PressResetButton();
break;
}
If you don’t need it for anything else you can drop resetFunction
The problem i have beats me thou but it seems it only affect the serial message so i dont really need it
for anything, was for troubleshooting.
Im just worried it will be the same for the actual message that i will send to the cloud but im not that far in the code yet.
You could also forget pinMode(pinResetButton, INPUT_PULLDOWN) if you use the three parameter constructor ClickButton stateResetButton(pinResetButton, HIGH, true) which attaches the pull-down for you.
I am trying to use this in one of my project which uses several buttons. How would I go about that? A comment in the code under “History” says: “Added another example code for multiple buttons in an object array” but I am not able to find such an example. I gave it a try anyway in my sketch as outlined below, but it only seems to work for Button1 but not for Button2 and Button 3.
In my sketch I just defined several instances like this:
@peekay123: Thanks, this way it works.I thought that the …clicks variable would exist for each of the instances created. And if not, should then …clicks not contain the respective value of the last instance refreshed by …Update (in my case it was for the one that was first called with Update)?
Anyway, thx for the quick reply.
This library is great and really usefull.
I needed something else that wasnt included so i added myself: report when the button is released after a long click.
Now it works like this for me:
if i set “reportRelease” as false, then it works as it was before. If i set it as true, then it will give me:
-2 after a long double click and 102 once the button is released. The same for any other amount of clicks.
100 + “amount of clicks” after released.
My questions is:
What should i do with this to share it? Create a new library? Update the clickbutton library?
@alexgrauer, cool stuff! I would say add the the new functions to the existing library, keeping the existing ones as-is for compatibility. Then, do a pull request against my github repo so I can update the code with your request. I’ll then publish it back to the IDE.
I did not create clickButton library and it is a unknown gem IMO. I’m glad folks are using and augmenting it. I look forward to seeing your pull request!
@peekay. Did it!!! … and i changed the code a bit to keep the compatibility.
Sorry im new to all this so im not sure i did the pull request correctly. Let me know please.
I have few products I’m developing and it would be nice if I could get by with only using 1 or 2 buttons to navigate the user interface on the LCD screen of the product.
I actually buy some equipment that has a single setup programming button where different button press times do different things. It works like a charm.