iv123 lin / Mbed OS connected-lights

Dependencies:   ChainableLED

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* lighting-system-firmware/source/main.cpp */
00002 
00003 #include "mbed.h"
00004 #include "led.h"    // Abstracts away the differens between the LED types
00005 
00006 // PIR sensor acts as an interrupt - signals us whenever it goes high (or low)
00007 InterruptIn pir(PIR_PIN);   // This pin value comes out mbed_app.json
00008 
00009 // Whenever movement is not detected
00010 void pir_fall() {
00011   setRgbColor(0.0f, 0.0f, 0.0f);
00012 }
00013 
00014 // Whenever movement is detected
00015 void pir_rise() {
00016   // set the color to red
00017   setRgbColor(1.0f, 0.0f, 0.0f);
00018 }
00019 
00020 int main(int, char**) {
00021   // Blink the LED when the application starts
00022   setRgbColor(0.0f, 1.0f, 0.0f);
00023   Thread::wait(500);
00024   setRgbColor(0.0f, 0.0f, 0.0f);
00025 
00026   // The PIR sensor uses interrupts, no need to poll
00027   pir.fall(&pir_fall);
00028   pir.rise(&pir_rise);
00029 }