Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RGBLED by
rgbled.cpp@1:a43483907ce0, 2015-01-29 (annotated)
- Committer:
- bohocode
- Date:
- Thu Jan 29 08:42:26 2015 +0000
- Revision:
- 1:a43483907ce0
- Parent:
- 0:7c0b6a649748
Added yellow, cyan and magenta.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rcflyair | 0:7c0b6a649748 | 1 | #include "mbed.h" |
rcflyair | 0:7c0b6a649748 | 2 | #include "rgbled.h" |
rcflyair | 0:7c0b6a649748 | 3 | |
rcflyair | 0:7c0b6a649748 | 4 | rgbled::rgbled(PinName pin_red, PinName pin_green, PinName pin_blue) |
rcflyair | 0:7c0b6a649748 | 5 | : _pin_red(pin_red), _pin_green(pin_green), _pin_blue(pin_blue){ |
rcflyair | 0:7c0b6a649748 | 6 | _on = false; |
rcflyair | 0:7c0b6a649748 | 7 | _off = !_on; |
rcflyair | 0:7c0b6a649748 | 8 | _pin_red = _off; |
rcflyair | 0:7c0b6a649748 | 9 | _pin_green = _off; |
rcflyair | 0:7c0b6a649748 | 10 | _pin_blue = _off; |
rcflyair | 0:7c0b6a649748 | 11 | } |
rcflyair | 0:7c0b6a649748 | 12 | |
rcflyair | 0:7c0b6a649748 | 13 | void rgbled::active(bool a){ |
rcflyair | 0:7c0b6a649748 | 14 | _on = a; |
rcflyair | 0:7c0b6a649748 | 15 | _off = !_on; |
rcflyair | 0:7c0b6a649748 | 16 | } |
rcflyair | 0:7c0b6a649748 | 17 | |
rcflyair | 0:7c0b6a649748 | 18 | void rgbled::_none(void){ |
rcflyair | 0:7c0b6a649748 | 19 | _pin_red = _off; |
rcflyair | 0:7c0b6a649748 | 20 | _pin_green = _off; |
rcflyair | 0:7c0b6a649748 | 21 | _pin_blue = _off; |
rcflyair | 0:7c0b6a649748 | 22 | } |
rcflyair | 0:7c0b6a649748 | 23 | |
rcflyair | 0:7c0b6a649748 | 24 | void rgbled::_red(void){ |
rcflyair | 0:7c0b6a649748 | 25 | _pin_red = _on; |
rcflyair | 0:7c0b6a649748 | 26 | _pin_green = _off; |
rcflyair | 0:7c0b6a649748 | 27 | _pin_blue = _off; |
rcflyair | 0:7c0b6a649748 | 28 | } |
rcflyair | 0:7c0b6a649748 | 29 | |
rcflyair | 0:7c0b6a649748 | 30 | void rgbled::_green(void){ |
rcflyair | 0:7c0b6a649748 | 31 | _pin_red = _off; |
rcflyair | 0:7c0b6a649748 | 32 | _pin_green = _on; |
rcflyair | 0:7c0b6a649748 | 33 | _pin_blue = _off; |
rcflyair | 0:7c0b6a649748 | 34 | } |
rcflyair | 0:7c0b6a649748 | 35 | |
rcflyair | 0:7c0b6a649748 | 36 | void rgbled::_blue(void){ |
rcflyair | 0:7c0b6a649748 | 37 | _pin_red = _off; |
rcflyair | 0:7c0b6a649748 | 38 | _pin_green = _off; |
rcflyair | 0:7c0b6a649748 | 39 | _pin_blue = _on; |
rcflyair | 0:7c0b6a649748 | 40 | } |
rcflyair | 0:7c0b6a649748 | 41 | |
bohocode | 1:a43483907ce0 | 42 | void rgbled::_cyan(void){ |
bohocode | 1:a43483907ce0 | 43 | _pin_red = _off; |
bohocode | 1:a43483907ce0 | 44 | _pin_green = _on; |
bohocode | 1:a43483907ce0 | 45 | _pin_blue = _on; |
bohocode | 1:a43483907ce0 | 46 | } |
bohocode | 1:a43483907ce0 | 47 | |
bohocode | 1:a43483907ce0 | 48 | void rgbled::_yellow(void){ |
bohocode | 1:a43483907ce0 | 49 | _pin_red = _on; |
bohocode | 1:a43483907ce0 | 50 | _pin_green = _on; |
bohocode | 1:a43483907ce0 | 51 | _pin_blue = _off; |
bohocode | 1:a43483907ce0 | 52 | } |
bohocode | 1:a43483907ce0 | 53 | |
bohocode | 1:a43483907ce0 | 54 | void rgbled::_magenta(void){ |
bohocode | 1:a43483907ce0 | 55 | _pin_red = _on; |
bohocode | 1:a43483907ce0 | 56 | _pin_green = _off; |
bohocode | 1:a43483907ce0 | 57 | _pin_blue = _on; |
bohocode | 1:a43483907ce0 | 58 | } |
bohocode | 1:a43483907ce0 | 59 | |
rcflyair | 0:7c0b6a649748 | 60 | void rgbled::set(color c){ |
rcflyair | 0:7c0b6a649748 | 61 | switch (c) { |
rcflyair | 0:7c0b6a649748 | 62 | case none : |
rcflyair | 0:7c0b6a649748 | 63 | _none(); |
rcflyair | 0:7c0b6a649748 | 64 | break; |
rcflyair | 0:7c0b6a649748 | 65 | case red : |
rcflyair | 0:7c0b6a649748 | 66 | _red(); |
rcflyair | 0:7c0b6a649748 | 67 | break; |
bohocode | 1:a43483907ce0 | 68 | case yellow : |
bohocode | 1:a43483907ce0 | 69 | _yellow(); |
bohocode | 1:a43483907ce0 | 70 | break; |
rcflyair | 0:7c0b6a649748 | 71 | case green : |
rcflyair | 0:7c0b6a649748 | 72 | _green(); |
rcflyair | 0:7c0b6a649748 | 73 | break; |
bohocode | 1:a43483907ce0 | 74 | case cyan: |
bohocode | 1:a43483907ce0 | 75 | _cyan(); |
bohocode | 1:a43483907ce0 | 76 | break; |
rcflyair | 0:7c0b6a649748 | 77 | case blue : |
rcflyair | 0:7c0b6a649748 | 78 | _blue(); |
rcflyair | 0:7c0b6a649748 | 79 | break; |
bohocode | 1:a43483907ce0 | 80 | case magenta : |
bohocode | 1:a43483907ce0 | 81 | _magenta(); |
bohocode | 1:a43483907ce0 | 82 | break; |
rcflyair | 0:7c0b6a649748 | 83 | } |
rcflyair | 0:7c0b6a649748 | 84 | } |