diff --git a/lichtschranke/polling/polling.ino b/lichtschranke/polling/polling.ino index 86141f3..763a6fc 100644 --- a/lichtschranke/polling/polling.ino +++ b/lichtschranke/polling/polling.ino @@ -18,12 +18,14 @@ unsigned long sw2_lastTimeMicros=0; float sensordistance = 0.37; //in meters -#define TIMESCOUNT 20 +/*#define TIMESCOUNT 20 uint8_t times_index=0; float times[TIMESCOUNT]; +*/ +int serialvalue=0; - +float kmhtriggermin=15; void setup() { pinMode(PIN_LED, OUTPUT); @@ -34,9 +36,9 @@ void setup() { digitalWrite(PIN_FLASH, HIGH); - for (uint8_t i=0;i 0) { + serialvalue = Serial.parseInt(); + Serial.print("#"); + Serial.println(serialvalue); + if (serialvalue>=1 && serialvalue <= 100){ + kmhtriggermin=serialvalue; + Serial.print("settrigger="); + Serial.println(kmhtriggermin); + } + + if (serialvalue==-1){ + digitalWrite(PIN_FLASH, LOW); //Trigger flash + delay(100); + digitalWrite(PIN_FLASH, HIGH); + } + + while (Serial.read() != '\n') { + //read until line ended + } + + } + if (sw1_released && !digitalRead(PIN_SW1)){ //pressed sw1_released=false; if (sw1_lastTime+SWDEBOUNCE=1){ - if (kmh>getTimesMax()){ + if (kmh>kmhtriggermin){ + // kmh>getTimesMax() digitalWrite(PIN_FLASH, LOW); //Trigger flash delay(100); digitalWrite(PIN_FLASH, HIGH); } - + + Serial.print("speed="); Serial.println(kmh); //Serial.println(" kmh"); //add time to last times queue - times_index++; + /*times_index++; times_index%=TIMESCOUNT-1; times[times_index]=kmh; - + */ } @@ -114,6 +140,8 @@ void loop() { } + +/* float getTimesMax(){ float timesmax=0; for (uint8_t i=0;i