iv123 lin
/
connected-lights
sample_pir-lights_rgb
lighting-system-firmware/source/main.cpp@0:7a352727249b, 2017-06-18 (annotated)
- Committer:
- iv123
- Date:
- Sun Jun 18 10:14:56 2017 +0000
- Revision:
- 0:7a352727249b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iv123 | 0:7a352727249b | 1 | /* lighting-system-firmware/source/main.cpp */ |
iv123 | 0:7a352727249b | 2 | |
iv123 | 0:7a352727249b | 3 | #include "mbed.h" |
iv123 | 0:7a352727249b | 4 | #include "led.h" // Abstracts away the differens between the LED types |
iv123 | 0:7a352727249b | 5 | |
iv123 | 0:7a352727249b | 6 | // PIR sensor acts as an interrupt - signals us whenever it goes high (or low) |
iv123 | 0:7a352727249b | 7 | InterruptIn pir(PIR_PIN); // This pin value comes out mbed_app.json |
iv123 | 0:7a352727249b | 8 | |
iv123 | 0:7a352727249b | 9 | // Whenever movement is not detected |
iv123 | 0:7a352727249b | 10 | void pir_fall() { |
iv123 | 0:7a352727249b | 11 | setRgbColor(0.0f, 0.0f, 0.0f); |
iv123 | 0:7a352727249b | 12 | } |
iv123 | 0:7a352727249b | 13 | |
iv123 | 0:7a352727249b | 14 | // Whenever movement is detected |
iv123 | 0:7a352727249b | 15 | void pir_rise() { |
iv123 | 0:7a352727249b | 16 | // set the color to red |
iv123 | 0:7a352727249b | 17 | setRgbColor(1.0f, 0.0f, 0.0f); |
iv123 | 0:7a352727249b | 18 | } |
iv123 | 0:7a352727249b | 19 | |
iv123 | 0:7a352727249b | 20 | int main(int, char**) { |
iv123 | 0:7a352727249b | 21 | // Blink the LED when the application starts |
iv123 | 0:7a352727249b | 22 | setRgbColor(0.0f, 1.0f, 0.0f); |
iv123 | 0:7a352727249b | 23 | Thread::wait(500); |
iv123 | 0:7a352727249b | 24 | setRgbColor(0.0f, 0.0f, 0.0f); |
iv123 | 0:7a352727249b | 25 | |
iv123 | 0:7a352727249b | 26 | // The PIR sensor uses interrupts, no need to poll |
iv123 | 0:7a352727249b | 27 | pir.fall(&pir_fall); |
iv123 | 0:7a352727249b | 28 | pir.rise(&pir_rise); |
iv123 | 0:7a352727249b | 29 | } |