Alarmanlage mit Sensorkit

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 #include "mbed.h"
00007 #include "platform/mbed_thread.h"
00008 
00009 
00010 int main()
00011 {
00012     // Initialise the digital pin LED1 as an output
00013     DigitalOut Lampe(PC_7);
00014     DigitalOut Sirene(PC_0);
00015     PortOut RGB(PortC,0b1110);
00016     DigitalIn Taste(PB_0);
00017     DigitalIn Magnetkontakt(PB_1);
00018     DigitalIn Mikrofon(PB_2);
00019     DigitalIn Lichtschranke(PB_3);
00020     bool scharf=false;
00021     int z=0;
00022     RGB=0;
00023     while (true) {
00024         if (Taste==0) 
00025         {
00026             wait_ms(20);
00027             scharf = !scharf;
00028             while(Taste==0);
00029             wait_ms(20);            
00030         }
00031         if (scharf)
00032         {
00033             Lampe=1;
00034             if (Magnetkontakt==0) Sirene=1;
00035             if (Mikrofon==0) 
00036             {
00037                 z++;
00038                 wait(1);
00039                 if (z==3) Sirene=1;
00040             }
00041             if (Lichtschranke==1) Sirene=1;
00042         }
00043         else
00044         {
00045            Sirene=0;
00046            Lampe=0; 
00047            z=0;
00048            RGB=0;
00049         }
00050         if (Sirene==1)
00051         {
00052             if (RGB==0) RGB=0b10;
00053             RGB=RGB<<1;           
00054             wait(1);
00055         }
00056     }
00057 }