South East USA
Offline
God Member
Karma: 2
Posts: 558
|
 |
« on: February 16, 2011, 08:38:09 am » |
I'm trying to understand how AnalogButtons works
How would I code the analog buttons do to this Btn1 to toggle intUserSelection between 2,4,6,8 or 10 (rolling back to 2 from 10) Btn2 runs the function 'SolenoidOn' (which sets pin4 high for a time determined by intUserSelection)
But then while in the SolenoidOn function, I want to have the option 'Press any key to cancel'
So I've really got two different operations for a button--the normal operation that it does, but then if SolenoidOn function is running, the buttons take on a new purpose, to abort the SolenoidOn operation
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9393
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #1 on: February 16, 2011, 08:42:45 am » |
Do you have code to share ? (please use # button) as these questions make not much sense without for me.
|
|
|
|
|
Logged
|
|
|
|
|
South East USA
Offline
God Member
Karma: 2
Posts: 558
|
 |
« Reply #2 on: February 16, 2011, 08:57:55 am » |
I'm trying to figure out how the code works to use AnalogButtons. So I don't have any code yet.
|
|
|
|
|
Logged
|
|
|
|
|
London, GB
Offline
Sr. Member
Karma: 7
Posts: 332
Nothing works.
|
 |
« Reply #3 on: February 16, 2011, 09:06:14 am » |
Analogue buttons are one of those things that nobody in the history of human understanding has ever understood. It has long been thought to be either a marketing phrase, or something lost in translation long ago that should have meant something entirely different.
|
|
|
|
|
Logged
|
|
|
|
|
South East USA
Offline
God Member
Karma: 2
Posts: 558
|
 |
« Reply #4 on: February 16, 2011, 09:12:30 am » |
Please?
|
|
|
|
|
Logged
|
|
|
|
|
Lancashire, UK
Offline
Edison Member
Karma: 8
Posts: 1988
|
 |
« Reply #5 on: February 16, 2011, 10:25:57 am » |
As in explain what an analog button is in your context. I've never heard of the phrase, and google mumbles on about Play Station controllers which isn't much help.
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Online
Tesla Member
Karma: 71
Posts: 6820
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #6 on: February 16, 2011, 11:05:21 am » |
What the heck is an AnalogButton?
______ Rob
|
|
|
|
|
Logged
|
|
|
|
|
Lancashire, UK
Offline
Edison Member
Karma: 8
Posts: 1988
|
 |
« Reply #7 on: February 16, 2011, 11:10:38 am » |
An oxymoron....... 
|
|
|
|
|
Logged
|
|
|
|
|
London, GB
Offline
Sr. Member
Karma: 7
Posts: 332
Nothing works.
|
 |
« Reply #8 on: February 16, 2011, 11:44:18 am » |
Ah, I think I get it. Shirt buttons, coat buttons, pyjama buttons, that sort of thing. Before digital clothing, buttons used to be manually operated, hence the confusion with the term “analogue”. We get the same thing in photography. New people who aren’t old enough discover film for the first time, and to differentiate it from the digital photography they know, they call film “analogue photography” erroneously.
|
|
|
|
« Last Edit: February 16, 2011, 03:37:11 pm by Ian Tindale »
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 276
Posts: 25482
Solder is electric glue
|
 |
« Reply #9 on: February 16, 2011, 12:52:29 pm » |
SouthernAtHeart You said:- I'm trying to understand how AnalogButtons works We don't know what your analogue button is. At a guess it is several push switches that short out some resistors with some connection to the analogue input pin. But that is just a guess and without a schematic even that is not sufficient to tell what you are on about. So post a link to these buttons or post a schematic of how you have wired them up please.
|
|
|
|
« Last Edit: February 16, 2011, 12:54:41 pm by Grumpy_Mike »
|
Logged
|
|
|
|
|
South East USA
Offline
God Member
Karma: 2
Posts: 558
|
 |
« Reply #10 on: February 16, 2011, 05:30:50 pm » |
http://www.arduino.cc/playground/Code/AnalogButtons...sorry, I thought everybody but me knew what they were, where the library was, and had used them numerous times. But upon googling 'AnalogButtons.h' I see I'm like the 2nd person that knows this library exists. Here's the sample code, I'm just hoping for a little more insight on how it works. /* 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 0
// 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) { if (held) { Serial.print("button id="); Serial.print(id); Serial.println(" was pressed and held"); } else{ Serial.print("button id="); Serial.print(id); Serial.println(" was pressed only"); } }
AnalogButtons analogButtons(ANALOG_PIN, 30, &handleButtons); Button b1 = Button(1, 1013,1014); Button b2 = Button(2, 1002, 1002); Button b3 = Button(3, 970, 971); Button b4 = Button(4, 929, 933); // Default hold duration is 1 second, lets make it 5 seconds for button5 Button b5 = Button(5, 860, 875, 5);
void setup() { Serial.begin(9600); Serial.println("Testing your Analog buttons"); analogButtons.addButton(b1); analogButtons.addButton(b2); analogButtons.addButton(b3); analogButtons.addButton(b4); analogButtons.addButton(b5); } 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); }
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 276
Posts: 25482
Solder is electric glue
|
 |
« Reply #11 on: February 16, 2011, 05:53:38 pm » |
I'm just hoping for a little more insight on how it works. Essentially it is a simple digital to analogue converter. You create different voltage outputs by bypassing different resistors, so that by reading the voltage on the output of this circuit you can work out what buttons were pressed. If you have this library then you use the result just like you would use a real button, to make decisions in your program. What you want to do is not too complex but it is not trivial either. You are best to draw out the flow you want your program to follow in the form of a flow diagram. However you need to learn some techniques first. I would recommend that you do, and understand the "blink without delay" example in the learning section.
|
|
|
|
|
Logged
|
|
|
|
|
London, GB
Offline
Sr. Member
Karma: 7
Posts: 332
Nothing works.
|
 |
« Reply #12 on: February 16, 2011, 08:05:13 pm » |
This is basically what is sometimes known as a “window discriminator”.
|
|
|
|
|
Logged
|
|
|
|
|
South East USA
Offline
God Member
Karma: 2
Posts: 558
|
 |
« Reply #13 on: February 16, 2011, 08:26:38 pm » |
Am I correct that analogButtons.checkButtons(); should be in my Loop routine, and then in the function void handleButtons(int id, boolean held) is where I actually put the commands to call different routines, depending on which button was pressed?
|
|
|
|
|
Logged
|
|
|
|
|
South East USA
Offline
God Member
Karma: 2
Posts: 558
|
 |
« Reply #14 on: February 16, 2011, 08:42:05 pm » |
...I'll be working on a Flow Chart in Excel, be back later, but I still hope someone answers my previous post, I think I'm correct in the way I understand it. A flow chart is a very good idea, thanks.
|
|
|
|
|
Logged
|
|
|
|
|
|