the analog input is connected to the breadboard via a 220 ohm resistor.
And the serial output result is displaying normally as the following:
value =
0
value =
1023
value =
1023
value =
497
value =
0
value =
642
value =
1023
value =
777
value =
21
value =
161
value =
985
value =
1023
value =
409
value =
0
value =
737
value =
1023
value =
685
value =
0
value =
434
value =
1023
value =
968
value =
150
value =
0
value =
993
value =
1023
value =
395
value =
0
value =
752
value =
1023
value =
669
value =
0
value =
448
value =
1023
value =
955
value =
141
value =
0
value =
1003
value =
1023
value =
582
value =
0
value =
549
value =
1023
value =
864
value =
74
value =
86
value =
1023
value =
1023
value =
494
value =
0
value =
649
value =
1023
value =
771
value =
17
and that's an expected behavior. But I don't know how can I read just the max value instead of reading all the different value.
My application is about reading max value per each button switch combination from a charlieplexing circuit.
See above reply. Please provide some more details.
Further
If you only want to display the highest value, use an additional variable to remember the highest value that you have measured and only print if the current reading is higher than the highest reading at present.
The only code you have shown us just reads a value from one pin.
If you have a much more complex requirement and the code to match then perhaps you should give details of that instead of just saying "doesn't fit my application" without any hint of what application is.
We're mostly not bad at programming but we're rubbish at mind-reading.
Do you mean that it dumps the highest value as related to each cycle? because I thought it's meant to measure the absolute highest value.
The technique will provide the highest value over a number of readings. How many readings you take and the source of the readings is up to you. If you need to read the highest value returned from any combination of 4 inputs and save the 16 values separately then it could do that as well.
kaisbensalah:
I'm willing to implement charlieplexing using 4 buttons and I need to find a unique value for the voltage from each button switch combination. So how this can be accomplished?
for starters a button is a digital input ie its either open(released) or closed(pressed). so what are you using analog input!
secondly if your IOs are not limited you better off having an individual input for each button since to charlieplex 4 button you would need 3 IOs!
if you insist on using analog input of you buttons, you need a threshold of when the button is ON and OFF. for example if you are using a pullup resistor at you arduino then when the button is not pressed the input see a HIGH (5V) and when its pressed the button pull the input to GND (0V) which is a LOW. you can choose a threshold of 2.5V (512 in your code) to detect a Press or release
sherzaad:
for starters a button is a digital input ie its either open(released) or closed(pressed). so what are you using analog input!
secondly if your IOs are not limited you better off having an individual input for each button since to charlieplex 4 button you would need 3 IOs!
if you insist on using analog input of you buttons, you need a threshold of when the button is ON and OFF. for example if you are using a pullup resistor at you arduino then when the button is not pressed the input see a HIGH (5V) and when its pressed the button pull the input to GND (0V) which is a LOW. you can choose a threshold of 2.5V (512 in your code) to detect a Press or release
I need to use one analog input per 4 buttons, because I need to connect many buttons using my card - that's why I'm going to use charlieplexing technique within my circuit.
UKHeliBob:
The technique will provide the highest value over a number of readings. How many readings you take and the source of the readings is up to you. If you need to read the highest value returned from any combination of 4 inputs and save the 16 values separately then it could do that as well.
Ok, that's what I am looking for. But as I'm new to Arduino, I don't know how this can be achieved. How this can be done using code?
The easiest way to do this is to press a combination of buttons and manually note the highest value returned over a period.
This calibration process is presumably not going to be done many times so it may not be worth the effort of trying to automate it. To do so you would need a method of determining whether a button was pressed or not and I assume that they are single pole switches leaving no spare contacts to read their state.
How are the buttons wired and what is connected when a button is pressed ?
UKHeliBob:
The easiest way to do this is to press a combination of buttons and manually note the highest value returned over a period.
This calibration process is presumably not going to be done many times so it may not be worth the effort of trying to automate it. To do so you would need a method of determining whether a button was pressed or not and I assume that they are single pole switches leaving no spare contacts to read their state.
How are the buttons wired and what is connected when a button is pressed ?