I could imagine if you are using a delay to do a debounce, that you would want to read both values first, then do the delay, and read them again and compare to the originals. Then just subtract. You probably don't want to do read first, delay, read first again, read second, delay, read second again.

I've read posts about allowing time for the ADC to switch and read the value of a different pin, does this still need to be put into consideration or is it handled internally? For example, if it were still relevant, you may find you get more stable readings from the following:

If you don't tell us what you have you will always get answers whoich might work -- but might not be the best or what you want. Maybe they are what you want. How would you know?

This is from the Mega 2560 Manual -- a comparator is built in. Surprise!

The Analog Comparator compares the input values on the positive pin AIN0 and negative pinAIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pinAIN1, the Analog Comparator output, ACO, is set. The comparator's output can be set to triggerthe Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separateinterrupt, exclusive to the Analog Comparator. The user can select Interrupt triggering on comparatoroutput rise, fall or toggle. A block diagram of the comparator and its surrounding logic isshown in Figure 24-1.

The Power Reduction ADC bit, PRADC, in "PRR0 - Power Reduction Register 0" on page 56must be disabled by writing a logical zero to be able to use the ADC input MUX.

I am a beginner and I have a school project to develop the Arduino Mega2560.It consists of 2 electrodes that are placed on the head. I have to measure the potential difference between them (because one of them is the reference), amplify the signal and make a chart.

My big problem is that I can not find and do not even know how to use differential inputs with gain (10x or 200x).Somebody please (with some urgency), can give me a code example?

You'll need an instrumentation amplifier to measure the difference in potential between two electrodes. The REF pin of the IA can be tied to 2.5V so that you can handle both positive and negative inputs.

50Hz or 60Hz mains interference may be a problem, unless you run everything from batteries and go to the middle of a field to take readings.. You will probably need to follow the IA with a notch filter to remove this, and then an op amp to provide further amplification before the signal is large enough for an Arduino to digitize.

However, you should consider the safety aspects. What would happen if the Arduino was being powered from USB, and the computer developed an earth fault? Medical EEG equipment has a high degree of isolation between the electrode amplifier module and the rest of the equipment, so as to be safe in the event of an equipment fault. One possibility is for you to power the Arduino from a battery while it is taking measurements, but then you won't be able to print the data directly to a chart. You could collect the data, save it to an SD card, and subsequently generate the chart from the data on the card.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Just want to input the differential input between two potentiometers (One reference and one feedback from a 12 V linear actuator. (will use a H-bridge BTN8982TA for arduino)The aim is to have to motor turning clokwise and conterclokwise to locate the actuator in the right position.

However, the brige with the two potentiometer can return values from +5 V Maxi left , 0 in middle position and -5V Max Right. Relative voltage between the two potentiometes cursors