add triggermin set over serial

This commit is contained in:
interfisch 2018-12-27 12:57:54 +01:00
parent 68270366ad
commit d98700dfbd
1 changed files with 37 additions and 8 deletions

View File

@ -18,12 +18,14 @@ unsigned long sw2_lastTimeMicros=0;
float sensordistance = 0.37; //in meters float sensordistance = 0.37; //in meters
#define TIMESCOUNT 20 /*#define TIMESCOUNT 20
uint8_t times_index=0; uint8_t times_index=0;
float times[TIMESCOUNT]; float times[TIMESCOUNT];
*/
int serialvalue=0;
float kmhtriggermin=15;
void setup() { void setup() {
pinMode(PIN_LED, OUTPUT); pinMode(PIN_LED, OUTPUT);
@ -34,9 +36,9 @@ void setup() {
digitalWrite(PIN_FLASH, HIGH); digitalWrite(PIN_FLASH, HIGH);
for (uint8_t i=0;i<TIMESCOUNT;i++){ /*for (uint8_t i=0;i<TIMESCOUNT;i++){
times[i]=15; times[i]=15;
} }*/
Serial.begin(115200); Serial.begin(115200);
@ -45,6 +47,28 @@ void setup() {
void loop() { void loop() {
//digitalWrite(PIN_LED, sw1_flag); //digitalWrite(PIN_LED, sw1_flag);
while (Serial.available() > 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 if (sw1_released && !digitalRead(PIN_SW1)){ //pressed
sw1_released=false; sw1_released=false;
if (sw1_lastTime+SWDEBOUNCE<millis()){ if (sw1_lastTime+SWDEBOUNCE<millis()){
@ -92,21 +116,23 @@ void loop() {
if (kmh>=1){ if (kmh>=1){
if (kmh>getTimesMax()){ if (kmh>kmhtriggermin){
// kmh>getTimesMax()
digitalWrite(PIN_FLASH, LOW); //Trigger flash digitalWrite(PIN_FLASH, LOW); //Trigger flash
delay(100); delay(100);
digitalWrite(PIN_FLASH, HIGH); digitalWrite(PIN_FLASH, HIGH);
} }
Serial.print("speed=");
Serial.println(kmh); Serial.println(kmh);
//Serial.println(" kmh"); //Serial.println(" kmh");
//add time to last times queue //add time to last times queue
times_index++; /*times_index++;
times_index%=TIMESCOUNT-1; times_index%=TIMESCOUNT-1;
times[times_index]=kmh; times[times_index]=kmh;
*/
} }
@ -114,6 +140,8 @@ void loop() {
} }
/*
float getTimesMax(){ float getTimesMax(){
float timesmax=0; float timesmax=0;
for (uint8_t i=0;i<TIMESCOUNT;i++){ for (uint8_t i=0;i<TIMESCOUNT;i++){
@ -123,3 +151,4 @@ float getTimesMax(){
} }
return timesmax; return timesmax;
} }
*/