123

Dependencies:   mbed DigitDisplay Grove_LCD_RGB_Backlight

Committer:
mashabozorgzad
Date:
Wed Apr 07 17:37:11 2021 +0000
Revision:
0:1e3da2405347
hjgjhgj

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mashabozorgzad 0:1e3da2405347 1 #include "mbed.h" // include the MBED library
mashabozorgzad 0:1e3da2405347 2 #include "DigitDisplay.h"
mashabozorgzad 0:1e3da2405347 3 #include "Grove_LCD_RGB_Backlight.h"
mashabozorgzad 0:1e3da2405347 4
mashabozorgzad 0:1e3da2405347 5 DigitDisplay display(D2,D3);
mashabozorgzad 0:1e3da2405347 6 Serial blue(D1,D0);
mashabozorgzad 0:1e3da2405347 7 Grove_LCD_RGB_Backlight LCD(D14,D15); // flash represents the LCD connect
mashabozorgzad 0:1e3da2405347 8 Grove_LCD_RGB_Backlight flash(D14,D15);
mashabozorgzad 0:1e3da2405347 9 InterruptIn PIR(D6);
mashabozorgzad 0:1e3da2405347 10 char buf[20];
mashabozorgzad 0:1e3da2405347 11 short motion_detected=0;
mashabozorgzad 0:1e3da2405347 12 void LOW(void);
mashabozorgzad 0:1e3da2405347 13 char bnum;
mashabozorgzad 0:1e3da2405347 14 int main()
mashabozorgzad 0:1e3da2405347 15 {
mashabozorgzad 0:1e3da2405347 16 // set button # to zero and shut off RGB leds
mashabozorgzad 0:1e3da2405347 17
mashabozorgzad 0:1e3da2405347 18 while(1) { // set up infinte loop
mashabozorgzad 0:1e3da2405347 19 //button number
mashabozorgzad 0:1e3da2405347 20 if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4
mashabozorgzad 0:1e3da2405347 21 {
mashabozorgzad 0:1e3da2405347 22 switch(bnum)
mashabozorgzad 0:1e3da2405347 23 {
mashabozorgzad 0:1e3da2405347 24 case '1':
mashabozorgzad 0:1e3da2405347 25
mashabozorgzad 0:1e3da2405347 26 LCD.clear();
mashabozorgzad 0:1e3da2405347 27 LCD.setRGB(0x00,0x80,0x00); //green lcd
mashabozorgzad 0:1e3da2405347 28 LCD.locate(0,1); //position for writing
mashabozorgzad 0:1e3da2405347 29 printf(buf,"ARM ALARM 2");
mashabozorgzad 0:1e3da2405347 30
mashabozorgzad 0:1e3da2405347 31 LCD.locate(1,1); //position next line
mashabozorgzad 0:1e3da2405347 32 printf(buf,"ALARM OFF 4");
mashabozorgzad 0:1e3da2405347 33
mashabozorgzad 0:1e3da2405347 34 break;
mashabozorgzad 0:1e3da2405347 35 case '2':
mashabozorgzad 0:1e3da2405347 36 LCD.clear();
mashabozorgzad 0:1e3da2405347 37 LCD.setRGB(0xff,0x00,0x00); //lcd red
mashabozorgzad 0:1e3da2405347 38 LCD.locate(0,1);
mashabozorgzad 0:1e3da2405347 39 printf(buf,"ALARM is ARMING");
mashabozorgzad 0:1e3da2405347 40 printf(buf,"please leave Now");
mashabozorgzad 0:1e3da2405347 41
mashabozorgzad 0:1e3da2405347 42 display.setBrightness(3); //brightness
mashabozorgzad 0:1e3da2405347 43 for (int count=10;count >0;count-- ) // count for 10 sec
mashabozorgzad 0:1e3da2405347 44 {
mashabozorgzad 0:1e3da2405347 45 display.write(count);
mashabozorgzad 0:1e3da2405347 46 wait(1000);
mashabozorgzad 0:1e3da2405347 47 }
mashabozorgzad 0:1e3da2405347 48
mashabozorgzad 0:1e3da2405347 49 LCD.setRGB(0x00,0x80,0x00); //lcd green
mashabozorgzad 0:1e3da2405347 50 PIR.fall(&LOW); // connect code at LOW to IRQ
mashabozorgzad 0:1e3da2405347 51
mashabozorgzad 0:1e3da2405347 52 if(motion_detected == 1) // if motion detected
mashabozorgzad 0:1e3da2405347 53 {
mashabozorgzad 0:1e3da2405347 54 motion_detected=0; // set variable to 0
mashabozorgzad 0:1e3da2405347 55 for(int Flash =0 ;Flash >5;Flash++){
mashabozorgzad 0:1e3da2405347 56 flash.setRGB(0xff,0xff,0xff); // set LCD to white
mashabozorgzad 0:1e3da2405347 57 wait_ms(500);
mashabozorgzad 0:1e3da2405347 58 flash.setRGB(0xff,0x00,0x00);
mashabozorgzad 0:1e3da2405347 59 } // set lcd to red // hold red colour for 0.5 seconds
mashabozorgzad 0:1e3da2405347 60 LCD.setRGB(0x80,0x00,0x80);
mashabozorgzad 0:1e3da2405347 61 printf(buf,"Alarm Sounding ");
mashabozorgzad 0:1e3da2405347 62 LCD.locate(1,1);
mashabozorgzad 0:1e3da2405347 63 printf(buf,"3 Disable ALarm");
mashabozorgzad 0:1e3da2405347 64
mashabozorgzad 0:1e3da2405347 65 }
mashabozorgzad 0:1e3da2405347 66
mashabozorgzad 0:1e3da2405347 67 break;
mashabozorgzad 0:1e3da2405347 68
mashabozorgzad 0:1e3da2405347 69
mashabozorgzad 0:1e3da2405347 70
mashabozorgzad 0:1e3da2405347 71 case '3':
mashabozorgzad 0:1e3da2405347 72 LCD.clear();
mashabozorgzad 0:1e3da2405347 73 LCD.setRGB(0x00,0x80,0x00);
mashabozorgzad 0:1e3da2405347 74 LCD.locate(0,1);
mashabozorgzad 0:1e3da2405347 75 printf(buf," ALARM DISARMED");
mashabozorgzad 0:1e3da2405347 76 LCD.locate(1,1);
mashabozorgzad 0:1e3da2405347 77 printf(buf,"2- ARM, 4- OFF");
mashabozorgzad 0:1e3da2405347 78 // DigitDisplay::off();
mashabozorgzad 0:1e3da2405347 79
mashabozorgzad 0:1e3da2405347 80
mashabozorgzad 0:1e3da2405347 81 case '4':
mashabozorgzad 0:1e3da2405347 82 LCD.setRGB(0x80,0x00,0x80);
mashabozorgzad 0:1e3da2405347 83 LCD.locate(0,1);
mashabozorgzad 0:1e3da2405347 84 printf(buf," ALARM IS about ");
mashabozorgzad 0:1e3da2405347 85 LCD.locate(1,1);
mashabozorgzad 0:1e3da2405347 86 printf(buf,"to Turn OFF ");
mashabozorgzad 0:1e3da2405347 87 wait_ms(2000);
mashabozorgzad 0:1e3da2405347 88 void displayOff();
mashabozorgzad 0:1e3da2405347 89 break;
mashabozorgzad 0:1e3da2405347 90
mashabozorgzad 0:1e3da2405347 91 default:
mashabozorgzad 0:1e3da2405347 92
mashabozorgzad 0:1e3da2405347 93 break;
mashabozorgzad 0:1e3da2405347 94
mashabozorgzad 0:1e3da2405347 95 }
mashabozorgzad 0:1e3da2405347 96 }
mashabozorgzad 0:1e3da2405347 97 }
mashabozorgzad 0:1e3da2405347 98 }
mashabozorgzad 0:1e3da2405347 99
mashabozorgzad 0:1e3da2405347 100
mashabozorgzad 0:1e3da2405347 101 void LOW(void)
mashabozorgzad 0:1e3da2405347 102 {
mashabozorgzad 0:1e3da2405347 103 motion_detected=1; // motion_detected ==1 motion
mashabozorgzad 0:1e3da2405347 104 }