While loop don't stop

I'm back...

This is my code:

int outputValue = 0;
int ledPin = 7; //led says when sampling starts
int button = 2; //button to start sampling

void setup() {
Serial.begin(9600);
Serial.println("CLEARDATA");
}

void loop() {

int meten = digitalRead(button); //looks at button: low or high

// while button is push, function meet() is called.

while (meten == HIGH) {
meet();
}
}

void meet() {

digitalWrite (ledPin, HIGH); //turns on the led for a second
delay(1000);
int sensorValue0 = analogRead(A0); //read analog 0
int sensorValue1 = analogRead(A1); //read analog 1
outputValue = map (sensorValue1, 0, 1023, 100, 2000); //converts analog1 to values between 100-2000

// send to serial (macro in excel)

Serial.print("DATA, ,");

Serial.println (sensorValue0);
delay(sensorValue1);
}

When I push the button, ' meten' is high.
And it starts to sample the SensorValues to Excel (with PLX-DAQ). It works! Fine!
But when I left the button, i think 'meten' is low and there is no call to void meet() and there is no sample of values.
Not so. The sample goes on.
Neither turn on the LED, in the first rule of meet().

What happened?

while (meten == HIGH) {
    meet();
  }

What here can make "meten" low again?

You need to do the read as part of the condition:

while (digitalRead(button) == HIGH) {
    meet();
  }

Thanks. It works.

But another problem:

The led don't go on for a second. And also the outputValue (which is linked at the delaytime of sampling) is not going to 100. But when I removed both rules (digitalWrite and delay(1000)) the sampling time is correct. So there is a conflict. I will during the sample, so long as the button is pressed turn on the led. Second experiment is a startbutton and a stopbutton.

Idea?

The led don't go on for a second.

I don't see where you turn the LED off.

Can you post you code again, please?

I never turns the led off.
It must be put ON! :~

In the first two rules of the function meet() I've digitalWrite (ledPin, HIGH).
Then a delay of 1000.
So, i think, the led turns on for a second.
But programming is seems to be difficult for me... =(

PS copying the code to this forum is a lot of work. I programmed on a standalone laptop, without any network/internet connection. So I have to copy my code in a txt, put it on a stick, go to anonther computer with internetconnection etc. etc. O, o, happy schoolnetwork...

So, i think, the led turns on for a second

No, the LED turns on for ever if you don't turn it off.

But the problem is: he don't even turn on. Why not?

Maybe you didn't set the LED pin to be an output.

And that's it!
A silly beginners mistake.

Thanks.

I will thank you all for answering and debugging me.

The first part of my project works!

Take a random sensor.
With potentiometer 1 you set the sample frequentie.
With potentiometer 2 you set the number of samples.
With the button you start sampling and put it in a column in Excel.

Now we must edit Excel to take a usefull graph of the data.

It seems to be very usefull for simply temperature, light, humidity measurements for our young students at school.
At higher classes they could edit the C-code.

But also is it very usefull for our exchange with a school in Macha (Zambia). There the people don't have the possibility to buy a expensive measuresystem. So this low-budget (< € 40) looks helpfull.

If there is anyone interested in this (little) project, contact me.

Thanks a lot!

Gr.
Johan