Code for the following project: https://www.instructables.com/id/Ultimate-Hamster-Tracker-Wheel-Featuring-Mbed-C-LC/
Dependencies: 4DGL-uLCD-SE PinDetect mbed
Shiftbrite.h@0:d0e2fe309777, 2017-04-03 (annotated)
- Committer:
- bstrickland9
- Date:
- Mon Apr 03 00:24:50 2017 +0000
- Revision:
- 0:d0e2fe309777
Code for the following project:; https://www.instructables.com/id/Ultimate-Hamster-Tracker-Wheel-Featuring-Mbed-C-LC/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bstrickland9 | 0:d0e2fe309777 | 1 | #include "mbed.h" |
bstrickland9 | 0:d0e2fe309777 | 2 | |
bstrickland9 | 0:d0e2fe309777 | 3 | //Setup a new class for a Shiftbrite RGB LED module |
bstrickland9 | 0:d0e2fe309777 | 4 | class Shiftbrite |
bstrickland9 | 0:d0e2fe309777 | 5 | { |
bstrickland9 | 0:d0e2fe309777 | 6 | public: |
bstrickland9 | 0:d0e2fe309777 | 7 | Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk); |
bstrickland9 | 0:d0e2fe309777 | 8 | void write(int red, int green, int blue); |
bstrickland9 | 0:d0e2fe309777 | 9 | |
bstrickland9 | 0:d0e2fe309777 | 10 | private: |
bstrickland9 | 0:d0e2fe309777 | 11 | //class sets up the pins |
bstrickland9 | 0:d0e2fe309777 | 12 | DigitalOut _pin_e; |
bstrickland9 | 0:d0e2fe309777 | 13 | DigitalOut _pin_l; |
bstrickland9 | 0:d0e2fe309777 | 14 | SPI _spi; |
bstrickland9 | 0:d0e2fe309777 | 15 | }; |
bstrickland9 | 0:d0e2fe309777 | 16 | |
bstrickland9 | 0:d0e2fe309777 | 17 | Shiftbrite::Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk) |
bstrickland9 | 0:d0e2fe309777 | 18 | : _pin_e(pin_e), _pin_l(pin_l), _spi(pin_do, pin_di, pin_clk) |
bstrickland9 | 0:d0e2fe309777 | 19 | { |
bstrickland9 | 0:d0e2fe309777 | 20 | _spi.format(16,0); |
bstrickland9 | 0:d0e2fe309777 | 21 | _spi.frequency(500000); |
bstrickland9 | 0:d0e2fe309777 | 22 | _pin_e=0; |
bstrickland9 | 0:d0e2fe309777 | 23 | _pin_l=0; |
bstrickland9 | 0:d0e2fe309777 | 24 | } |
bstrickland9 | 0:d0e2fe309777 | 25 | |
bstrickland9 | 0:d0e2fe309777 | 26 | void Shiftbrite::write(int red, int green, int blue) |
bstrickland9 | 0:d0e2fe309777 | 27 | { |
bstrickland9 | 0:d0e2fe309777 | 28 | _pin_e=0; |
bstrickland9 | 0:d0e2fe309777 | 29 | _pin_l=0; |
bstrickland9 | 0:d0e2fe309777 | 30 | unsigned int low_color=0; |
bstrickland9 | 0:d0e2fe309777 | 31 | unsigned int high_color=0; |
bstrickland9 | 0:d0e2fe309777 | 32 | high_color=(blue<<4)|((red&0x3C0)>>6); |
bstrickland9 | 0:d0e2fe309777 | 33 | low_color=(((red&0x3F)<<10)|(green)); |
bstrickland9 | 0:d0e2fe309777 | 34 | _spi.write(high_color); |
bstrickland9 | 0:d0e2fe309777 | 35 | _spi.write(low_color); |
bstrickland9 | 0:d0e2fe309777 | 36 | _pin_l=1; |
bstrickland9 | 0:d0e2fe309777 | 37 | _pin_l=0; |
bstrickland9 | 0:d0e2fe309777 | 38 | } |