what i have to change?
void loop () {
pulse= digitalRead (anag);
tasto= digitalRead (testo);
if (tasto == HIGH ){
val= millis ();
while (millis () - val < 30000 ) {
if ( pulse == HIGH ); {
cont ++;
}
}}
for ( int i=0; i < cont ; i++) {
digitalWrite ( led,LOW );
delay (500);
digitalWrite ( led,HIGH);
delay (500);
}}
A lot. First, put every { on a new line. Second, put every } on a new line Close curly braces NEVER get doubled up one line.
Third, delete the useless blank lines, and use Tools +Auto Format. Then, your loop function will like this:
void loop ()
{
pulse= digitalRead (anag);
tasto= digitalRead (testo);
if (tasto == HIGH )
{
val= millis ();
while (millis () - val < 30000 )
{
if ( pulse == HIGH );
{
cont ++;
}
}
}
for ( int i=0; i < cont ; i++)
{
digitalWrite ( led,LOW );
delay (500);
digitalWrite ( led,HIGH);
delay (500);
}
}
Now, look at that while loop. It will loop for 30 seconds. During that time, it will test whether pulse is HIGH. If it is, it will do nothing (;). Otherwise, it will do nothing. Then, it will increment cont.
Even if you remove the incorrectly placed ;, the code is still wrong. What causes pulse to change in the while loop? Nothing. So, if pulse is HIGH at the start, you will count as fast as you can, for 30 seconds. If it is LOW to start with, you will do nothing for 30 seconds.
You need to read a value for pulse in the while loop.
But, you do NOT want to be counting pulses if the pin IS HIGH. You want to increment the counter once when the pin BECOMES HIGH. Look at the state change detection example to see how that is done.