han back
/
CLEO_INTRUDER_DETECTION_SYSTEM
SMART CLEO Intruder Detection System
main.cpp@0:98b619522ddd, 2017-12-06 (annotated)
- Committer:
- SMART_CLEO
- Date:
- Wed Dec 06 08:54:55 2017 +0000
- Revision:
- 0:98b619522ddd
SMART_CLEO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SMART_CLEO | 0:98b619522ddd | 1 | #include "mbed.h" |
SMART_CLEO | 0:98b619522ddd | 2 | |
SMART_CLEO | 0:98b619522ddd | 3 | PinName pin_BUZZER = PD_2; |
SMART_CLEO | 0:98b619522ddd | 4 | PinName pin_PIR = PB_2; |
SMART_CLEO | 0:98b619522ddd | 5 | |
SMART_CLEO | 0:98b619522ddd | 6 | // I2C address |
SMART_CLEO | 0:98b619522ddd | 7 | int DoT_ADDR = 0x71<<1; |
SMART_CLEO | 0:98b619522ddd | 8 | |
SMART_CLEO | 0:98b619522ddd | 9 | DigitalOut Buzzer(pin_BUZZER); |
SMART_CLEO | 0:98b619522ddd | 10 | InterruptIn Pir(pin_PIR); |
SMART_CLEO | 0:98b619522ddd | 11 | I2C Dotmatrix(I2C_SDA, I2C_SCL); |
SMART_CLEO | 0:98b619522ddd | 12 | |
SMART_CLEO | 0:98b619522ddd | 13 | //char Data_BUF[17] = {0, 0x28, 0, 0x28, 0, 0xBA, 0, 0xBA, 0, 0x7C, 0, 0x10, 0, 0x38, 0, 0x38, 0}; |
SMART_CLEO | 0:98b619522ddd | 14 | char Data_BUF[17] = {0, 0x14, 0, 0x14, 0, 0x5D, 0, 0x5D, 0, 0x3E, 0, 0x08, 0, 0x1C, 0, 0x1C, 0}; |
SMART_CLEO | 0:98b619522ddd | 15 | char Clear_BUF[17] = {0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
SMART_CLEO | 0:98b619522ddd | 16 | volatile int pir_flag = 0, Intruder_flag = 0, Blink_flag = 0; |
SMART_CLEO | 0:98b619522ddd | 17 | |
SMART_CLEO | 0:98b619522ddd | 18 | void PIR_ISR(void); |
SMART_CLEO | 0:98b619522ddd | 19 | void data_write(char *data, int len); |
SMART_CLEO | 0:98b619522ddd | 20 | void Command_Write(uint8_t com); |
SMART_CLEO | 0:98b619522ddd | 21 | void Dotmatrix_init(void); |
SMART_CLEO | 0:98b619522ddd | 22 | |
SMART_CLEO | 0:98b619522ddd | 23 | int main() |
SMART_CLEO | 0:98b619522ddd | 24 | { |
SMART_CLEO | 0:98b619522ddd | 25 | Dotmatrix_init(); |
SMART_CLEO | 0:98b619522ddd | 26 | data_write(Clear_BUF, 17); |
SMART_CLEO | 0:98b619522ddd | 27 | |
SMART_CLEO | 0:98b619522ddd | 28 | Pir.rise(&PIR_ISR); |
SMART_CLEO | 0:98b619522ddd | 29 | Buzzer = 0; |
SMART_CLEO | 0:98b619522ddd | 30 | |
SMART_CLEO | 0:98b619522ddd | 31 | while(1){ |
SMART_CLEO | 0:98b619522ddd | 32 | if(pir_flag == 1) |
SMART_CLEO | 0:98b619522ddd | 33 | { |
SMART_CLEO | 0:98b619522ddd | 34 | Intruder_flag = 1; |
SMART_CLEO | 0:98b619522ddd | 35 | pir_flag = 0; |
SMART_CLEO | 0:98b619522ddd | 36 | } |
SMART_CLEO | 0:98b619522ddd | 37 | else |
SMART_CLEO | 0:98b619522ddd | 38 | { |
SMART_CLEO | 0:98b619522ddd | 39 | Intruder_flag = 0; |
SMART_CLEO | 0:98b619522ddd | 40 | } |
SMART_CLEO | 0:98b619522ddd | 41 | if((Intruder_flag == 1) && (Blink_flag ==0)) |
SMART_CLEO | 0:98b619522ddd | 42 | { |
SMART_CLEO | 0:98b619522ddd | 43 | Blink_flag = 1; |
SMART_CLEO | 0:98b619522ddd | 44 | data_write(Data_BUF, 17); |
SMART_CLEO | 0:98b619522ddd | 45 | Buzzer = 1; |
SMART_CLEO | 0:98b619522ddd | 46 | } |
SMART_CLEO | 0:98b619522ddd | 47 | else |
SMART_CLEO | 0:98b619522ddd | 48 | { |
SMART_CLEO | 0:98b619522ddd | 49 | Blink_flag = 0; |
SMART_CLEO | 0:98b619522ddd | 50 | data_write(Clear_BUF, 17); |
SMART_CLEO | 0:98b619522ddd | 51 | Buzzer = 0; |
SMART_CLEO | 0:98b619522ddd | 52 | } |
SMART_CLEO | 0:98b619522ddd | 53 | wait(0.5); |
SMART_CLEO | 0:98b619522ddd | 54 | } |
SMART_CLEO | 0:98b619522ddd | 55 | } |
SMART_CLEO | 0:98b619522ddd | 56 | |
SMART_CLEO | 0:98b619522ddd | 57 | void PIR_ISR(void) |
SMART_CLEO | 0:98b619522ddd | 58 | { |
SMART_CLEO | 0:98b619522ddd | 59 | pir_flag = 1; |
SMART_CLEO | 0:98b619522ddd | 60 | } |
SMART_CLEO | 0:98b619522ddd | 61 | |
SMART_CLEO | 0:98b619522ddd | 62 | void data_write(char *data, int len) |
SMART_CLEO | 0:98b619522ddd | 63 | { |
SMART_CLEO | 0:98b619522ddd | 64 | data[0] = 0; |
SMART_CLEO | 0:98b619522ddd | 65 | Dotmatrix.write(DoT_ADDR, data, len); |
SMART_CLEO | 0:98b619522ddd | 66 | } |
SMART_CLEO | 0:98b619522ddd | 67 | |
SMART_CLEO | 0:98b619522ddd | 68 | void Command_Write(char com) |
SMART_CLEO | 0:98b619522ddd | 69 | { |
SMART_CLEO | 0:98b619522ddd | 70 | Dotmatrix.write(DoT_ADDR, &com, 1); |
SMART_CLEO | 0:98b619522ddd | 71 | } |
SMART_CLEO | 0:98b619522ddd | 72 | |
SMART_CLEO | 0:98b619522ddd | 73 | void Dotmatrix_init(void) |
SMART_CLEO | 0:98b619522ddd | 74 | { |
SMART_CLEO | 0:98b619522ddd | 75 | // Internal System Clock enable |
SMART_CLEO | 0:98b619522ddd | 76 | Command_Write((char)0x21); |
SMART_CLEO | 0:98b619522ddd | 77 | // INT/ROW output pin Set -> ROW Driver output |
SMART_CLEO | 0:98b619522ddd | 78 | Command_Write((char)0xA0); |
SMART_CLEO | 0:98b619522ddd | 79 | // Dimming Set -> 15 |
SMART_CLEO | 0:98b619522ddd | 80 | Command_Write((char)0xEF); |
SMART_CLEO | 0:98b619522ddd | 81 | // Blinking Set -> off |
SMART_CLEO | 0:98b619522ddd | 82 | // Display Set -> on |
SMART_CLEO | 0:98b619522ddd | 83 | Command_Write((char)0x81); |
SMART_CLEO | 0:98b619522ddd | 84 | } |