jim hamblen
/
Shiftbrite_Demo
Simple demo for a ShiftBrite RGB LED module that cycles through different colors.
main.cpp@0:fc7fc9c0cd67, 2011-04-22 (annotated)
- Committer:
- 4180_1
- Date:
- Fri Apr 22 14:31:29 2011 +0000
- Revision:
- 0:fc7fc9c0cd67
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:fc7fc9c0cd67 | 1 | #include "mbed.h" |
4180_1 | 0:fc7fc9c0cd67 | 2 | //ShiftBrite Demo |
4180_1 | 0:fc7fc9c0cd67 | 3 | DigitalOut latch(p15); |
4180_1 | 0:fc7fc9c0cd67 | 4 | DigitalOut enable(p16); |
4180_1 | 0:fc7fc9c0cd67 | 5 | //Cycles through different colors on RGB LED |
4180_1 | 0:fc7fc9c0cd67 | 6 | SPI spi(p11, p12, p13); |
4180_1 | 0:fc7fc9c0cd67 | 7 | //Use SPI hardware to write color values to LED driver chip |
4180_1 | 0:fc7fc9c0cd67 | 8 | void RGB_LED(int red, int green, int blue) { |
4180_1 | 0:fc7fc9c0cd67 | 9 | unsigned int low_color=0; |
4180_1 | 0:fc7fc9c0cd67 | 10 | unsigned int high_color=0; |
4180_1 | 0:fc7fc9c0cd67 | 11 | high_color=(blue<<4)|((red&0x3C0)>>6); |
4180_1 | 0:fc7fc9c0cd67 | 12 | low_color=(((red&0x3F)<<10)|(green)); |
4180_1 | 0:fc7fc9c0cd67 | 13 | spi.write(high_color); |
4180_1 | 0:fc7fc9c0cd67 | 14 | spi.write(low_color); |
4180_1 | 0:fc7fc9c0cd67 | 15 | latch=1; |
4180_1 | 0:fc7fc9c0cd67 | 16 | latch=0; |
4180_1 | 0:fc7fc9c0cd67 | 17 | } |
4180_1 | 0:fc7fc9c0cd67 | 18 | |
4180_1 | 0:fc7fc9c0cd67 | 19 | int main() { |
4180_1 | 0:fc7fc9c0cd67 | 20 | int red=0; |
4180_1 | 0:fc7fc9c0cd67 | 21 | int green=0; |
4180_1 | 0:fc7fc9c0cd67 | 22 | int blue=0; |
4180_1 | 0:fc7fc9c0cd67 | 23 | spi.format(16,0); |
4180_1 | 0:fc7fc9c0cd67 | 24 | spi.frequency(500000); |
4180_1 | 0:fc7fc9c0cd67 | 25 | enable=0; |
4180_1 | 0:fc7fc9c0cd67 | 26 | latch=0; |
4180_1 | 0:fc7fc9c0cd67 | 27 | wait(2); |
4180_1 | 0:fc7fc9c0cd67 | 28 | for (red = 0; red<50; red = red+10) { |
4180_1 | 0:fc7fc9c0cd67 | 29 | for (blue = 0; blue<50; blue = blue+10) { |
4180_1 | 0:fc7fc9c0cd67 | 30 | for (green = 0; green<50; green = green+10) |
4180_1 | 0:fc7fc9c0cd67 | 31 | |
4180_1 | 0:fc7fc9c0cd67 | 32 | { |
4180_1 | 0:fc7fc9c0cd67 | 33 | RGB_LED( red, green, blue); |
4180_1 | 0:fc7fc9c0cd67 | 34 | wait(.25); |
4180_1 | 0:fc7fc9c0cd67 | 35 | } |
4180_1 | 0:fc7fc9c0cd67 | 36 | } |
4180_1 | 0:fc7fc9c0cd67 | 37 | } |
4180_1 | 0:fc7fc9c0cd67 | 38 | |
4180_1 | 0:fc7fc9c0cd67 | 39 | } |