Got it, (I think) delchrys, try this: (And translate to . . . Dutch?)
const int threshold = 400;
const int ledPinRood = 8;
const int ledPinGroen = 9;
unsigned int time = 0;
int pulseCount = 0;
int pulseCount2 = 0;
unsigned long start, fin; //NEW
bool swState, oldSwState; //NEW
const byte sw = 10; //NEW one side of switch to GND,
//other to pin 10
void setup() {
Serial.begin(9600);
pinMode(ledPinRood, OUTPUT);
pinMode(ledPinGroen, OUTPUT);
//pinMode(10, INPUT);
pinMode(sw, INPUT_PULLUP); //NEW
}
void loop() {
swState = digitalRead(sw);
if (swState != oldSwState)
{
start = millis();
oldSwState = swState;
}
if(swState)
fin = 30 * 1000UL; // 30 seconds for testing
else
fin = 1000UL;
if (millis() - start > fin)
{
start += fin;
int sensorValue = analogRead(A5);
int sensorValue2 = analogRead(A7);
int switchvalue = digitalRead(10);
Serial.print("Sensor 1: ");
Serial.print(sensorValue);
Serial.print(" -----------//////-------------- ");
Serial.print("Sensor 2: ");
Serial.println(sensorValue2);
Serial.println(switchvalue);
Serial.println(pulseCount);
Serial.println(pulseCount2);
if (sensorValue > threshold) {
pulseCount++;
}
else
{
pulseCount = 0;
}
if (sensorValue2 > threshold) {
pulseCount2++;
}
else pulseCount2 = 0;
if (pulseCount > 6 | pulseCount2 > 6) {
digitalWrite(ledPinRood, HIGH);
digitalWrite(ledPinGroen, LOW);
}
else {
digitalWrite(ledPinRood, LOW);
digitalWrite(ledPinGroen, HIGH);
}
}
}