///////////////////////////////////////////////////////////////////// // Author: RSP @ ESL (Embedded System Lab), KMUTNB // Date: 2014-APR-03 // Target Board: Arduino (ATmega328P, 5V, 16MHz) // Arduino IDE: version 1.0.5 // Description: // This Arduino sketch demonstrates how to implement a simple human // motion detection system based on the AMN34112 sensor module. // When the motion is detected, the system triggers an alarm // (LED blinking and buzzer sound). //////////////////////////////////////////////////////////////////////// /* Board INT0 INT1 INT2 INT3 INT4 INT5 Uno, Ethernet 2 3 Mega2560 2 3 21 20 19 18 Leonardo 3 2 0 1 7 */ #define ALARM_PIN (3) #define BLINK_TIME_MS (1000) #define WAIT_TIME_MS (3000) typedef enum {ST_CHECK=0, ST_ALARM, ST_WAIT} state_type; state_type state; uint32_t ts; volatile uint16_t event_count = 0; void eint_isr() { event_count++; } void setup() { pinMode( ALARM_PIN, OUTPUT ); digitalWrite( ALARM_PIN, LOW ); delay( 3000 ); ts = millis(); event_count = 0; state = ST_CHECK; attachInterrupt( 0, eint_isr, RISING ); // use INT0 } void loop() { static uint8_t led_state = 0; switch (state) { case ST_CHECK: if ( event_count > 1 ) { state = ST_ALARM; // change state to ST_ALARM ts = millis(); // update timestamp } break; case ST_ALARM: if ( millis() - ts >= BLINK_TIME_MS ) { state = ST_WAIT; // change state to ST_WAIT ts = millis(); led_state = 0; digitalWrite( ALARM_PIN, led_state ); // turn off alarm } else { led_state ^= 1; digitalWrite( ALARM_PIN, led_state ); // toggle alarm delay(50); } break; case ST_WAIT: if ( millis() - ts >= WAIT_TIME_MS ) { event_count = 0; // reset event counter state = ST_CHECK; } break; default: state = ST_CHECK; break; } } ////////////////////////////////////////////////////////////////////////
วันอาทิตย์ที่ 24 กุมภาพันธ์ พ.ศ. 2562
"Embedded Space"
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
มินิโปรเจค Arduino Calculator (แก้ไข)
https://www.electronicshub.org/arduino-calculator/ #include <LiquidCrystal.h> ...
-
void setup() { DDRD = 0xFF; // เซ็ตให้ขา 0 - 7 เป็นเอาต์พุต PORTD = 0xF9 ; // เซ็ตให้แสดงค่า 0xF9 ออกไป (แสดงเลข 1 ใน 7 Segment C...
-
void setup() { pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinM...
-
https://www.electronicshub.org/arduino-calculator/ #include <LiquidCrystal.h> ...
ไม่มีความคิดเห็น:
แสดงความคิดเห็น