![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
123
Dependencies: mbed DigitDisplay Grove_LCD_RGB_Backlight
labproject.cpp
- Committer:
- mashabozorgzad
- Date:
- 2021-04-07
- Revision:
- 0:1e3da2405347
File content as of revision 0:1e3da2405347:
#include "mbed.h" // include the MBED library #include "DigitDisplay.h" #include "Grove_LCD_RGB_Backlight.h" DigitDisplay display(D2,D3); Serial blue(D1,D0); Grove_LCD_RGB_Backlight LCD(D14,D15); // flash represents the LCD connect Grove_LCD_RGB_Backlight flash(D14,D15); InterruptIn PIR(D6); char buf[20]; short motion_detected=0; void LOW(void); char bnum; int main() { // set button # to zero and shut off RGB leds while(1) { // set up infinte loop //button number if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4 { switch(bnum) { case '1': LCD.clear(); LCD.setRGB(0x00,0x80,0x00); //green lcd LCD.locate(0,1); //position for writing printf(buf,"ARM ALARM 2"); LCD.locate(1,1); //position next line printf(buf,"ALARM OFF 4"); break; case '2': LCD.clear(); LCD.setRGB(0xff,0x00,0x00); //lcd red LCD.locate(0,1); printf(buf,"ALARM is ARMING"); printf(buf,"please leave Now"); display.setBrightness(3); //brightness for (int count=10;count >0;count-- ) // count for 10 sec { display.write(count); wait(1000); } LCD.setRGB(0x00,0x80,0x00); //lcd green PIR.fall(&LOW); // connect code at LOW to IRQ if(motion_detected == 1) // if motion detected { motion_detected=0; // set variable to 0 for(int Flash =0 ;Flash >5;Flash++){ flash.setRGB(0xff,0xff,0xff); // set LCD to white wait_ms(500); flash.setRGB(0xff,0x00,0x00); } // set lcd to red // hold red colour for 0.5 seconds LCD.setRGB(0x80,0x00,0x80); printf(buf,"Alarm Sounding "); LCD.locate(1,1); printf(buf,"3 Disable ALarm"); } break; case '3': LCD.clear(); LCD.setRGB(0x00,0x80,0x00); LCD.locate(0,1); printf(buf," ALARM DISARMED"); LCD.locate(1,1); printf(buf,"2- ARM, 4- OFF"); // DigitDisplay::off(); case '4': LCD.setRGB(0x80,0x00,0x80); LCD.locate(0,1); printf(buf," ALARM IS about "); LCD.locate(1,1); printf(buf,"to Turn OFF "); wait_ms(2000); void displayOff(); break; default: break; } } } } void LOW(void) { motion_detected=1; // motion_detected ==1 motion }