Miskin Project
/
Renbed_RGB_Digital
Basic control of an RGB LED
main.cpp@3:3411d8922bb1, 2016-04-20 (annotated)
- Committer:
- MiskinPrj
- Date:
- Wed Apr 20 08:37:57 2016 +0000
- Revision:
- 3:3411d8922bb1
- Parent:
- 2:c936f86e62fb
changed on and off variables to const type
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MiskinPrj | 0:b4aa4b3a7cee | 1 | /********************************************************* |
MiskinPrj | 0:b4aa4b3a7cee | 2 | *Renbed_RGB_Digital * |
MiskinPrj | 2:c936f86e62fb | 3 | *Author: Elijah Orr & Dan Argust * |
MiskinPrj | 0:b4aa4b3a7cee | 4 | * * |
MiskinPrj | 0:b4aa4b3a7cee | 5 | *A program that controls an RGB LED * |
MiskinPrj | 0:b4aa4b3a7cee | 6 | *********************************************************/ |
MiskinPrj | 0:b4aa4b3a7cee | 7 | |
MiskinPrj | 0:b4aa4b3a7cee | 8 | /* include the mbed library made by mbed.org that contains |
MiskinPrj | 0:b4aa4b3a7cee | 9 | classes/functions designed to make programming mbed |
MiskinPrj | 0:b4aa4b3a7cee | 10 | microcontrollers easier */ |
MiskinPrj | 0:b4aa4b3a7cee | 11 | #include "mbed.h" |
MiskinPrj | 0:b4aa4b3a7cee | 12 | |
MiskinPrj | 0:b4aa4b3a7cee | 13 | /* Set up 3 pins as digital out to control the colour |
MiskinPrj | 0:b4aa4b3a7cee | 14 | cathodes of the RGB LED */ |
MiskinPrj | 1:56810f863198 | 15 | DigitalOut Red(P1_24); |
MiskinPrj | 1:56810f863198 | 16 | DigitalOut Green(P1_26); |
MiskinPrj | 1:56810f863198 | 17 | DigitalOut Blue(P0_19); |
MiskinPrj | 0:b4aa4b3a7cee | 18 | |
MiskinPrj | 2:c936f86e62fb | 19 | /* Set the on and off states of the lights */ |
MiskinPrj | 3:3411d8922bb1 | 20 | const int on = 0; |
MiskinPrj | 3:3411d8922bb1 | 21 | const int off = 1; |
MiskinPrj | 0:b4aa4b3a7cee | 22 | |
MiskinPrj | 0:b4aa4b3a7cee | 23 | int main() |
MiskinPrj | 0:b4aa4b3a7cee | 24 | { |
MiskinPrj | 0:b4aa4b3a7cee | 25 | /* open a for loop with no parameters to start an infinite loop */ |
MiskinPrj | 0:b4aa4b3a7cee | 26 | for(;;){ |
MiskinPrj | 0:b4aa4b3a7cee | 27 | Red = off; |
MiskinPrj | 0:b4aa4b3a7cee | 28 | Blue = off; |
MiskinPrj | 0:b4aa4b3a7cee | 29 | Green = off; |
MiskinPrj | 0:b4aa4b3a7cee | 30 | wait_ms(1000); |
MiskinPrj | 0:b4aa4b3a7cee | 31 | |
MiskinPrj | 0:b4aa4b3a7cee | 32 | Red = on; |
MiskinPrj | 0:b4aa4b3a7cee | 33 | wait_ms(1000); |
MiskinPrj | 0:b4aa4b3a7cee | 34 | |
MiskinPrj | 0:b4aa4b3a7cee | 35 | Red = off; |
MiskinPrj | 0:b4aa4b3a7cee | 36 | Green = on; |
MiskinPrj | 0:b4aa4b3a7cee | 37 | wait_ms(1000); |
MiskinPrj | 0:b4aa4b3a7cee | 38 | |
MiskinPrj | 0:b4aa4b3a7cee | 39 | Green = off; |
MiskinPrj | 0:b4aa4b3a7cee | 40 | Blue = on; |
MiskinPrj | 0:b4aa4b3a7cee | 41 | wait_ms(1000); |
MiskinPrj | 0:b4aa4b3a7cee | 42 | } |
MiskinPrj | 0:b4aa4b3a7cee | 43 | } |
MiskinPrj | 0:b4aa4b3a7cee | 44 | |
MiskinPrj | 0:b4aa4b3a7cee | 45 |