|
楼主 |
发表于 2019-9-23 19:49:24
|
显示全部楼层
- /*
- 【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
- 实验一百一十九:HB100微波雷达感应模块 10.525GHz多普勒探测器探头传感器
- 项目:测试HB100模块,输入改为模拟口A0,三组数据输出
- */
- #define RADAR A0 // RADAR inut is attached to A0
- #define MICRODELAY 100 // 100microseconds ~10000hz
- #define MAXINDEX 1024 // 10 bits
- #define TOPINDEX 1023 // 10 bits
- byte collect[MAXINDEX];
- int mean;
- int minimum;
- int maximum;
- int hysteresis; // 1/16 of max-min
- bool currentphase; // are value above mean + hysteresis;
- int lastnull; // index for last null passing value
- int prevnull; // index for previous null passing value
- int deltaindex;
- int deltadeltaindex;
- int index;
- bool phasechange = false;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- while (!Serial) {}
- index = 0;
- mean = 0;
- maximum = 255;
- minimum = 0;
- hysteresis = 0;
- currentphase = false;
- lastnull = 0;
- prevnull = 0;
- Serial.print("deltadeltaindex");
- Serial.print("\t");
- Serial.print("deltaindex");
- Serial.print("\t");
- Serial.println("delta");
- }
- void loop() {
- int newVal = analogRead(RADAR); // Raw reading from amplified radar
- mean -= (collect[index] >> 2);
- mean += (newVal >> 2);
- collect[index]= newVal;
- minimum = newVal < minimum ? newVal : minimum + 1;
- maximum = newVal > maximum ? newVal : maximum - 1;
- hysteresis = abs(maximum - minimum) >> 5;
- if(newVal > (mean + hysteresis))
- {
- if(false == currentphase)
- {
- currentphase = true;
- phasechange = true;
- }
- }
- else if(newVal < (mean - hysteresis))
- {
- if(currentphase)
- {
- currentphase = false;
- phasechange = true;
- }
- }
- if(phasechange)
- {
- prevnull = lastnull;
- lastnull = index;
- int delta = (prevnull > lastnull) ?
- (lastnull - prevnull + MAXINDEX) :
- (lastnull - prevnull);
- deltadeltaindex = abs(deltaindex - delta);
- deltaindex = delta;
- Serial.print(deltadeltaindex);
- Serial.print("\t");
- Serial.print(deltaindex);
- Serial.print("\t");
- Serial.println(delta);
- }
-
- index = index == TOPINDEX ? 0 : index + 1;
- phasechange = false;
- //delayMicroseconds(10);
- }
复制代码 |
|