AnalogButtons

Ciao a tutti.

Ho costruito la tastiera analogica di Acorrias


http://www.acorrias.it/?Arduino:Tastiera_analogica e funziona benissimo, non ho trovato esempi pero' per gestirla meglio, nel senso che con l'empio inserito nella parte void loop vi è la funzione "analogButtons.checkButtons();" che non riesco ad usare, nel senso che se premo 1 vado ad eseguire un parte di programma 2 un altra e così via .

Grazie in anticipo

Ciao gslow
incolla il codice che descrivi opppure il link per scaricarli.
Ciao Uwe

Ciao Uwe ecco il codice:

/*
AnalogButtons,

created 02 Jan 2009 V 0.1

Connect more than one button to a single analog pin,
register a call-back function.which gets called when a button
is pressed or held down for the defined number of seconds. Includes
software key debouncing which may need to be adjusted, the the second
argument to AnalogButtons class. Define the ANALOG_PIN in the constructor
of AnalogButtons.

The circuit:

  • 5 buttons, 1 side of all buttons connected together to +5V.
    The other side of each button is connected via a different value
    resister (tested with) 1k, 2k5, 5k8, 10k, 18k to one side of a
    100k resister which is in turn connected to GND. At the point
    where all the different resisters are joined you make a connection
    to your analog input. Basicly a different voltage divider is setup
    depending upon which button is pressed. You have to configure the
    Buttons Hi/Low values, see the comments in example code below and the
    AnalogButtons::configure(ANALOG_PIN) function.

More or less than 5 buttons could be added, just pick different values
of the resister sot hat all buttons have different values which arn't too
close in size.

I'm not sure what happens when Arduino is powered from batteries and Power V
drops below V5.

by Neil DUdman and everyone who's ever used Arduino

*/
#include "AnalogButtons.h"

#define ANALOG_PIN 4
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// A call back function that you pass into the constructor of AnalogButtons, see example
// below. Alternitivly you could extend the Button class and re-define the methods pressed()
// or held() which are called
void handleButtons(int id, boolean held)
{
lcd.clear();

if (held) {
lcd.print(id);lcd.print(" ^-^");
// Serial.print("button id="); Serial.print(id); Serial.println(" was pressed and held");
} else{
lcd.print(id);lcd.print(" ^");
//Serial.print("button id="); Serial.print(id); Serial.println(" was pressed only");
}
}

AnalogButtons analogButtons(ANALOG_PIN, 30, &handleButtons);
Button b1 = Button(1, 0,5);
Button b2 = Button(2, 129, 130);
Button b3 = Button(3, 272, 273);
Button b4 = Button(4, 574, 575);
// Default hold duration is 1 second, lets make it 5 seconds for button5
Button b5 = Button(5, 433, 434, 5);
Button b6 = Button(6, 835, 838);
Button b7 = Button(7, 710, 714);

void setup()
{
Serial.begin(9600);
Serial.println("Testing your Analog buttons");
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
analogButtons.addButton(b1);
analogButtons.addButton(b2);
analogButtons.addButton(b3);
analogButtons.addButton(b4);
analogButtons.addButton(b5);
analogButtons.addButton(b6);
analogButtons.addButton(b7);
}

void loop()
{
// To check values when button are pressed
analogButtons.checkButtons();

// To configure the MAX/Min values for each
// Button, uncomment this line, make sure you've called Serial.begin(9600);
// Then in turn hold town each botton, noting the max/min values
//AnalogButtons::configure(ANALOG_PIN); //delay(1000);
}

Io mi fermo qui nel void loop

// To check values when button are pressed
analogButtons.checkButtons();

ma come faccio a gestire eventi con la funzione analogButtons.checkButtons();

lo so che è banale ma in questi giorni il mio cervello è in tilt sarà la primavera. >:( :frowning:

Urca !! Argomento difficile 70 letture e nussun commento ?

Oppure sono io che sono antipatico al forum ? :-/

Ciao guarda anche a me interessa, decisamente interessante questa rete di pulsanti resistiva. Qualcuno ha idea come funzioni e come si capisca tramite un singolo input quale sto schiacciando?
Forse tutti i pulsanti sono chiusi e quando schiaccio apro facendo passare un tot voltaggio in rapporto alla resistenza montata al pulsante e quindi sapendo che resistenza sta a che pulsante capire che pulsante sto schiacciando? :o

Riscriviti tu le funzioni!!
non è difficile, non è codice cosi' avanzato.