Dependencies: PinDetect mbed Servo
door_leds.cpp@0:81f78497df4e, 2012-06-18 (annotated)
- Committer:
- Rufaida
- Date:
- Mon Jun 18 17:47:17 2012 +0000
- Revision:
- 0:81f78497df4e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rufaida | 0:81f78497df4e | 1 | #include "door_leds.h" |
Rufaida | 0:81f78497df4e | 2 | |
Rufaida | 0:81f78497df4e | 3 | /*definitions*/ |
Rufaida | 0:81f78497df4e | 4 | DigitalOut latch (p8); //Connecting the latch of the LED driver to (pin 8) of the embed |
Rufaida | 0:81f78497df4e | 5 | SPI port(p5, p6, p7); //Using the SPI pins in the embed |
Rufaida | 0:81f78497df4e | 6 | SPI spi(p5, p6, p7); |
Rufaida | 0:81f78497df4e | 7 | int LED_Pos; |
Rufaida | 0:81f78497df4e | 8 | int Level; |
Rufaida | 0:81f78497df4e | 9 | Ticker timer; |
Rufaida | 0:81f78497df4e | 10 | |
Rufaida | 0:81f78497df4e | 11 | /*finction to know the level (top or bottom) and the total LEDS and the flashing*/ |
Rufaida | 0:81f78497df4e | 12 | void Open_Close_Door(int i) { |
Rufaida | 0:81f78497df4e | 13 | Level=i; |
Rufaida | 0:81f78497df4e | 14 | LED_Pos=24; //The total LED for each door is 2x24 |
Rufaida | 0:81f78497df4e | 15 | } |
Rufaida | 0:81f78497df4e | 16 | |
Rufaida | 0:81f78497df4e | 17 | /*Function for the Ticker (LED doors update)*/ |
Rufaida | 0:81f78497df4e | 18 | |
Rufaida | 0:81f78497df4e | 19 | void DOORS_LED (void) { |
Rufaida | 0:81f78497df4e | 20 | if (LED_Pos) { |
Rufaida | 0:81f78497df4e | 21 | |
Rufaida | 0:81f78497df4e | 22 | spi.write(door_leds[Level][--LED_Pos]); |
Rufaida | 0:81f78497df4e | 23 | latch=1; |
Rufaida | 0:81f78497df4e | 24 | latch=0; |
Rufaida | 0:81f78497df4e | 25 | if (LED_Pos==0) |
Rufaida | 0:81f78497df4e | 26 | new_event(ev_Timeout); |
Rufaida | 0:81f78497df4e | 27 | } |
Rufaida | 0:81f78497df4e | 28 | } |
Rufaida | 0:81f78497df4e | 29 | |
Rufaida | 0:81f78497df4e | 30 | /*The Ticker function to start opening and closing the door*/ |
Rufaida | 0:81f78497df4e | 31 | |
Rufaida | 0:81f78497df4e | 32 | void Starting_LEDS (void) { |
Rufaida | 0:81f78497df4e | 33 | latch=0; |
Rufaida | 0:81f78497df4e | 34 | spi.format (16,0); |
Rufaida | 0:81f78497df4e | 35 | spi.write(0xFFFF); |
Rufaida | 0:81f78497df4e | 36 | latch=1; |
Rufaida | 0:81f78497df4e | 37 | latch=0; |
Rufaida | 0:81f78497df4e | 38 | LED_Pos=0; |
Rufaida | 0:81f78497df4e | 39 | timer.attach(&DOORS_LED,0.2); |
Rufaida | 0:81f78497df4e | 40 | } |