The purpose of this project was to create a system that would allow users to monitor a locked device using a Bluetooth device. This Bluetooth device will show the last user that unlocked the device, and also allows the user to unlock the device using the Bluetooth device. This device can be physically unlocked using a capacitive touch keypad sensor.
Dependencies: mbed Motor Servo
Fork of SerialPassthrough_LPC1768 by
Shiftbrite.h@7:79d0b30fedb4, 2016-03-15 (annotated)
- Committer:
- ewilliams61
- Date:
- Tue Mar 15 19:14:45 2016 +0000
- Revision:
- 7:79d0b30fedb4
Works :)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ewilliams61 | 7:79d0b30fedb4 | 1 | #include "mbed.h" |
ewilliams61 | 7:79d0b30fedb4 | 2 | |
ewilliams61 | 7:79d0b30fedb4 | 3 | //Setup a new class for a Shiftbrite RGB LED module |
ewilliams61 | 7:79d0b30fedb4 | 4 | class Shiftbrite |
ewilliams61 | 7:79d0b30fedb4 | 5 | { |
ewilliams61 | 7:79d0b30fedb4 | 6 | public: |
ewilliams61 | 7:79d0b30fedb4 | 7 | Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk); |
ewilliams61 | 7:79d0b30fedb4 | 8 | void write(int red, int green, int blue); |
ewilliams61 | 7:79d0b30fedb4 | 9 | |
ewilliams61 | 7:79d0b30fedb4 | 10 | private: |
ewilliams61 | 7:79d0b30fedb4 | 11 | //class sets up the pins |
ewilliams61 | 7:79d0b30fedb4 | 12 | DigitalOut _pin_e; |
ewilliams61 | 7:79d0b30fedb4 | 13 | DigitalOut _pin_l; |
ewilliams61 | 7:79d0b30fedb4 | 14 | SPI _spi; |
ewilliams61 | 7:79d0b30fedb4 | 15 | }; |
ewilliams61 | 7:79d0b30fedb4 | 16 | |
ewilliams61 | 7:79d0b30fedb4 | 17 | Shiftbrite::Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk) |
ewilliams61 | 7:79d0b30fedb4 | 18 | : _pin_e(pin_e), _pin_l(pin_l), _spi(pin_do, pin_di, pin_clk) |
ewilliams61 | 7:79d0b30fedb4 | 19 | { |
ewilliams61 | 7:79d0b30fedb4 | 20 | _pin_e=0; |
ewilliams61 | 7:79d0b30fedb4 | 21 | _pin_l=0; |
ewilliams61 | 7:79d0b30fedb4 | 22 | } |
ewilliams61 | 7:79d0b30fedb4 | 23 | |
ewilliams61 | 7:79d0b30fedb4 | 24 | void Shiftbrite::write(int red, int green, int blue) |
ewilliams61 | 7:79d0b30fedb4 | 25 | { |
ewilliams61 | 7:79d0b30fedb4 | 26 | long colors=0; |
ewilliams61 | 7:79d0b30fedb4 | 27 | long c=00; |
ewilliams61 | 7:79d0b30fedb4 | 28 | |
ewilliams61 | 7:79d0b30fedb4 | 29 | red=red*4; |
ewilliams61 | 7:79d0b30fedb4 | 30 | green=green*4; |
ewilliams61 | 7:79d0b30fedb4 | 31 | blue=blue*4; |
ewilliams61 | 7:79d0b30fedb4 | 32 | |
ewilliams61 | 7:79d0b30fedb4 | 33 | if(red>1023){ |
ewilliams61 | 7:79d0b30fedb4 | 34 | red=1023; |
ewilliams61 | 7:79d0b30fedb4 | 35 | } |
ewilliams61 | 7:79d0b30fedb4 | 36 | if(green>1023){ |
ewilliams61 | 7:79d0b30fedb4 | 37 | green=1023; |
ewilliams61 | 7:79d0b30fedb4 | 38 | } |
ewilliams61 | 7:79d0b30fedb4 | 39 | if(blue>1023){ |
ewilliams61 | 7:79d0b30fedb4 | 40 | blue=1023; |
ewilliams61 | 7:79d0b30fedb4 | 41 | } |
ewilliams61 | 7:79d0b30fedb4 | 42 | colors=(colors<<2)|(c&3); |
ewilliams61 | 7:79d0b30fedb4 | 43 | colors=(colors<<10)|(blue&1023); |
ewilliams61 | 7:79d0b30fedb4 | 44 | colors=(colors<<10)|(red&1023); |
ewilliams61 | 7:79d0b30fedb4 | 45 | colors=(colors<<10)|(green&1023); |
ewilliams61 | 7:79d0b30fedb4 | 46 | |
ewilliams61 | 7:79d0b30fedb4 | 47 | long s1=0xFF000000; |
ewilliams61 | 7:79d0b30fedb4 | 48 | long s2=0xFF0000; |
ewilliams61 | 7:79d0b30fedb4 | 49 | long s3=0xFF00; |
ewilliams61 | 7:79d0b30fedb4 | 50 | long s4=0xFF; |
ewilliams61 | 7:79d0b30fedb4 | 51 | |
ewilliams61 | 7:79d0b30fedb4 | 52 | _spi.write((s1&colors)>>24); |
ewilliams61 | 7:79d0b30fedb4 | 53 | _spi.write((s2&colors)>>16); |
ewilliams61 | 7:79d0b30fedb4 | 54 | _spi.write((s3&colors)>>8); |
ewilliams61 | 7:79d0b30fedb4 | 55 | _spi.write(s4&colors); |
ewilliams61 | 7:79d0b30fedb4 | 56 | _pin_l=1; |
ewilliams61 | 7:79d0b30fedb4 | 57 | _pin_l=0; |
ewilliams61 | 7:79d0b30fedb4 | 58 | } |