-
Notifications
You must be signed in to change notification settings - Fork 0
/
radar.ino
94 lines (74 loc) · 2.17 KB
/
radar.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//**************************************************************//
// Name : radar //
// Author : Hendrik Dietrich, Karsten Schlachter //
// Date : Oktober 2016 //
// Version : 1.0 //
// Notes : Steuerung fuer Anzeigetafel Modelblitzer //
//****************************************************************
const int gndPIN=2;
const int radarPIN=7;
const int flashPIN=5;
const int CLEMENS = 30;
const unsigned long TIMEOUT=2000015000;
//frequenbestimmung mit singalgenerator getestet...min bis 20khz brauchbar (hoeher nicht probiert)
void setup() {
// put your setup code here, to run once:
pinMode(radarPIN,INPUT);
pinMode(gndPIN,OUTPUT);
pinMode(flashPIN,OUTPUT);
digitalWrite(gndPIN,LOW);
Serial.begin(9600);
}
unsigned long duration;
unsigned long oldduration=0;
unsigned long freq;
unsigned long v;
unsigned long lastFlash;
byte vkmh;
#define VMAX 30
#define LAMBDA 0.0321
unsigned long getDuration(){
unsigned long dur=0;
unsigned long buff;
for(int i=0;i<2;i++){
buff=pulseIn(radarPIN,LOW,TIMEOUT);// 10ms timeout
if(buff==0) return 0;
//Serial.println(buff);
dur+=buff;
buff= pulseIn(radarPIN,HIGH,TIMEOUT);
if(buff==0) return 0;//Serial.println(buff);
dur+=buff;
}
// Serial.println(dur);
return dur/2;
}
void loop() {
if((millis()-lastFlash)>100){
digitalWrite(flashPIN,LOW);
}
// kein 50/50, sondern variierender "duty cyle", daher high und low messen
duration=pulseIn(radarPIN,LOW,TIMEOUT);
// duration+=pulseIn(7,HIGH,TIMEOUT);
if(duration!=0){
duration=getDuration();
/* if(oldduration!=0){
duration=(oldduration*3+duration)/4;
}
oldduration=duration;*/
}
if(duration){
// duration/=20;
freq=1000000/duration;
vkmh=LAMBDA/4*freq*3.6*16;
// vkmh=v*3.6;
//duration=digitalRead(7);
// if(vkmh!=0 && vkmh<1200)
Serial.write(vkmh);
// Serial.println(vkmh);
if(vkmh>CLEMENS && (millis()-lastFlash)>5000){
lastFlash=millis();
digitalWrite(flashPIN,HIGH);
}
}
//delay(500);
}