Pour se projet, je disposais de 2 boutons poussoir bâtiment.
Je voulais que chaque bouton puisse fournir plusieurs informations, comme les doubles clicks ou les appuie long. J'ai donc cherché si un projet utilisait cette
fonction avec un Arduino. J'ai trouvé les exemples suivants :
- www.arduino.cc/playground/Code/Button
- jmsarduino.blogspot.com/2009/10/4-way-button-click-double-click-hold.html
Sur ce dernier blog, je me suis rappelé qu'il fallait faire un traitement (www.arduino.cc/en/Tutorial/Debounce) sur les entrées pour éviter des faux positifs.
Avec les infos de la page d'exemple pour créer une librairie
perso (www.arduino.cc/en/Hacking/LibraryTutorial),
j'ai décidé de créer une librairie Arduino "FWB", pour "Four Way
Button".
FWB.h
Pour ajouter une telle librairie à votre code, copier ce fichier dans le même répertoire que votre fichier .pde.
2 commentaires:
Hi,
I have downloaded and installed your library. I had to change the include to Arduino.h to compile it, but it looks like it should work now.
Could you provide an example of how to use it with two or more buttons please?
Also, can you confirm if the buttons are set as INPUT_PULLUP?
Thanks,
Luke
Hi,
Effectively, the #include "WProgram.h" need to be changed to #include "arduino.h". The FWB.h file come from my Arduino Emulator who compile the file with #include "WProgram.h"
As a complet example to use this class, you can see the file here : https://code.google.com/p/arduino-emulator/source/browse/trunk/Arduino/Stairlight.cpp
It's my complet project, but you can find how to use it in the setup().
By default, the buttons are set to : INPUT
(you can see this in the Configure(int pin, int pullMode) method)
However, you can reverse the system by changing the pullMode : detect when the input is true or false for a click
This project is a little old for me, I'm not 100% sure of everything I've done
Best regards
Jeremy
Enregistrer un commentaire