PRO2_Team 1_collected code
Dependencies: mbed
rgb_led.cpp@2:b80b6c14f7c3, 2017-05-19 (annotated)
- Committer:
- Hammer4400
- Date:
- Fri May 19 19:16:27 2017 +0000
- Revision:
- 2:b80b6c14f7c3
- Parent:
- 0:21e9cc38dd31
+setting & logging;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OlgaHoeyer | 0:21e9cc38dd31 | 1 | /* |
OlgaHoeyer | 0:21e9cc38dd31 | 2 | ================================================================================ |
OlgaHoeyer | 0:21e9cc38dd31 | 3 | == == == |
OlgaHoeyer | 0:21e9cc38dd31 | 4 | == Source File: == main.cpp == |
OlgaHoeyer | 0:21e9cc38dd31 | 5 | == File Name: == rgb_led.cpp == |
OlgaHoeyer | 0:21e9cc38dd31 | 6 | == Author: == Poul Erik Tjørnfelt == |
OlgaHoeyer | 0:21e9cc38dd31 | 7 | == Date: == 07/05-2017 == |
OlgaHoeyer | 0:21e9cc38dd31 | 8 | == Copyright: == Open to all == |
OlgaHoeyer | 0:21e9cc38dd31 | 9 | == Version: == 0.6 - Creation of file. == |
OlgaHoeyer | 0:21e9cc38dd31 | 10 | == == == |
OlgaHoeyer | 0:21e9cc38dd31 | 11 | == Description: == The .cpp file for a class, that creates instances of == |
OlgaHoeyer | 0:21e9cc38dd31 | 12 | == == the actual RGB lamp that is used. == |
OlgaHoeyer | 0:21e9cc38dd31 | 13 | == == == |
OlgaHoeyer | 0:21e9cc38dd31 | 14 | ================================================================================ |
OlgaHoeyer | 0:21e9cc38dd31 | 15 | */ |
OlgaHoeyer | 0:21e9cc38dd31 | 16 | |
OlgaHoeyer | 0:21e9cc38dd31 | 17 | #include "mbed.h" |
OlgaHoeyer | 0:21e9cc38dd31 | 18 | #include "rgb_led.h" |
OlgaHoeyer | 0:21e9cc38dd31 | 19 | |
OlgaHoeyer | 0:21e9cc38dd31 | 20 | RGB_LED::RGB_LED(PinName pin_R, PinName pin_G, PinName pin_B) |
OlgaHoeyer | 0:21e9cc38dd31 | 21 | :pin_r(pin_R), pin_g(pin_G), pin_b(pin_B) // Constructor |
OlgaHoeyer | 0:21e9cc38dd31 | 22 | { |
OlgaHoeyer | 0:21e9cc38dd31 | 23 | |
OlgaHoeyer | 0:21e9cc38dd31 | 24 | } |
OlgaHoeyer | 0:21e9cc38dd31 | 25 | |
OlgaHoeyer | 0:21e9cc38dd31 | 26 | void RGB_LED::set(float red,float green, float blue) |
OlgaHoeyer | 0:21e9cc38dd31 | 27 | { |
OlgaHoeyer | 0:21e9cc38dd31 | 28 | pin_r = red; // The amount of the single colours that we want in the |
OlgaHoeyer | 0:21e9cc38dd31 | 29 | pin_g = green; // actual colour (ex. purple = 0.7f, 0.0, 0.7f), gotten from |
OlgaHoeyer | 0:21e9cc38dd31 | 30 | pin_b = blue; // www.w3schools.com/colors/colors_picker.asp. |
OlgaHoeyer | 0:21e9cc38dd31 | 31 | /* |
OlgaHoeyer | 0:21e9cc38dd31 | 32 | We only use red, orange (2 parts red, 1 part green), green and blue. |
OlgaHoeyer | 0:21e9cc38dd31 | 33 | */ |
OlgaHoeyer | 0:21e9cc38dd31 | 34 | } |
OlgaHoeyer | 0:21e9cc38dd31 | 35 | |
OlgaHoeyer | 0:21e9cc38dd31 | 36 | void RGB_LED::flash(float period, float on_timer) |
OlgaHoeyer | 0:21e9cc38dd31 | 37 | { |
OlgaHoeyer | 0:21e9cc38dd31 | 38 | pin_r.period(period); // Sets the period in seconds of the LED. |
OlgaHoeyer | 0:21e9cc38dd31 | 39 | pin_r.write(on_timer); // The %age of the period that the LED is turned on. |
OlgaHoeyer | 0:21e9cc38dd31 | 40 | pin_g.period(period); |
OlgaHoeyer | 0:21e9cc38dd31 | 41 | pin_g.write(on_timer); |
OlgaHoeyer | 0:21e9cc38dd31 | 42 | pin_b.period(period); |
OlgaHoeyer | 0:21e9cc38dd31 | 43 | pin_b.write(on_timer); |
OlgaHoeyer | 0:21e9cc38dd31 | 44 | } |