Hi Johan,
Define a state machine that switches between two states DISCONNECTED and CONNECTED depending on the signal from the button. Check the code below and you will see that it will only read once.
(partial code)
#define DISCONNECTED 0
#define CONNECTED 1
int state = DISCONNECTED;
bool makeMeasurement = false;
void setup()
{
...
}
void loop()
{
// HANDLE STATEMACHINE
int B = analogRead(buttonPin); // assume LOW if pressed
if (state == DISCONNECTED && B == LOW)
{
state = CONNECTED;
makeMeasurement = true;
}
else
if (state == CONNECTED && B == HIGH)
{
state = DISCONNECTED;
}
// HANDLE MEASUREMENT
if (makeMeasurement)
{
makeMeasurement = false;
int z = analogRead(A0);
Serial.println(z);
}
}
as said not tested but you should get it,
succes