#define currentLimit 150 // Net ff onder de 2.5A#define sampleInterval 5#define trackPower 13#define currentSensePinA A0void shortCircuit() { static byte previousTime = 0; static byte shortCircuitCounter = 10; // static variabelen houden hun waardes vast. byte currentTime = millis() & 0xff; // we willen alleen de achterste byte van de 4 hebben if(currentTime - previousTime >= sampleInterval) { previousTime = currentTime; if(digitalRead(trackPower) == true) { // if track power is on, monitor the current if(analogRead(currentSensePinA) >= currentLimit) { // if current exceeds limit if(shortCircuitCounter) { shortCircuitCounter--; }// start counting down to 0... if(shortCircuitCounter == 0) { // and cut of the power digitalWrite(trackPower, LOW); shortCircuitCounter = 250; // we use the same timer to enable track power in 2,5 seconds } } else { // if current does not exceed limit, force the counter to 25 shortCircuitCounter = 10; } } else { // if track power OFF if(shortCircuitCounter) { shortCircuitCounter--; } // count down to 0... if(shortCircuitCounter == 0) { // and re-enable power after 2.5 seonds digitalWrite(trackPower, HIGH); shortCircuitCounter = 10; // restart timer for short circuit protection. } } }}