![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
This is how i got the hardware to work. Not saying that it cant work any other way. I haven't tied anything of yours in. So likely delete mine from rev 2 or 3, and then put this instead. Then it might work.
Dependencies: mbed
rgb_led.cpp@0:c426396d5fdf, 2017-06-22 (annotated)
- Committer:
- PET
- Date:
- Thu Jun 22 04:45:01 2017 +0000
- Revision:
- 0:c426396d5fdf
If you wanted to work on it, or look at it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PET | 0:c426396d5fdf | 1 | /* |
PET | 0:c426396d5fdf | 2 | -------------------------------------------------------------------------------- |
PET | 0:c426396d5fdf | 3 | -- Project: PRO2 "Awareness and Optimisation of energy consumption" |
PET | 0:c426396d5fdf | 4 | -- Team: Team 1 |
PET | 0:c426396d5fdf | 5 | |
PET | 0:c426396d5fdf | 6 | -- File Name: rgb_led.cpp |
PET | 0:c426396d5fdf | 7 | -- Author: Poul Erik Tjørnfelt |
PET | 0:c426396d5fdf | 8 | -- Date: 07/05-2017 |
PET | 0:c426396d5fdf | 9 | -- Copyright: Open to all |
PET | 0:c426396d5fdf | 10 | -- Version: 0.6 - Creation of file. |
PET | 0:c426396d5fdf | 11 | -- 1.0 - Finished version. |
PET | 0:c426396d5fdf | 12 | -- |
PET | 0:c426396d5fdf | 13 | -- Description: The .cpp file for a class, that creates instances of |
PET | 0:c426396d5fdf | 14 | -- the actual RGB lamp that is used. |
PET | 0:c426396d5fdf | 15 | -- |
PET | 0:c426396d5fdf | 16 | -- |
PET | 0:c426396d5fdf | 17 | -------------------------------------------------------------------------------- |
PET | 0:c426396d5fdf | 18 | */ |
PET | 0:c426396d5fdf | 19 | |
PET | 0:c426396d5fdf | 20 | #include "mbed.h" |
PET | 0:c426396d5fdf | 21 | #include "rgb_led.h" |
PET | 0:c426396d5fdf | 22 | |
PET | 0:c426396d5fdf | 23 | RGB_LED::RGB_LED(PinName pin_R, PinName pin_G, PinName pin_B) |
PET | 0:c426396d5fdf | 24 | :pin_r(pin_R), pin_g(pin_G), pin_b(pin_B) // Constructor |
PET | 0:c426396d5fdf | 25 | { |
PET | 0:c426396d5fdf | 26 | |
PET | 0:c426396d5fdf | 27 | } |
PET | 0:c426396d5fdf | 28 | |
PET | 0:c426396d5fdf | 29 | void RGB_LED::set(float red,float green, float blue) |
PET | 0:c426396d5fdf | 30 | { |
PET | 0:c426396d5fdf | 31 | pin_r = red; // The amount of the single colours that we want in the |
PET | 0:c426396d5fdf | 32 | pin_g = green; // actual colour (ex. purple = 0.7f, 0.0, 0.7f), gotten from |
PET | 0:c426396d5fdf | 33 | pin_b = blue; // www.w3schools.com/colors/colors_picker.asp. |
PET | 0:c426396d5fdf | 34 | /* |
PET | 0:c426396d5fdf | 35 | We only use red, orange (2 parts red, 1 part green), green and blue. |
PET | 0:c426396d5fdf | 36 | */ |
PET | 0:c426396d5fdf | 37 | } |
PET | 0:c426396d5fdf | 38 | |
PET | 0:c426396d5fdf | 39 | void RGB_LED::flash(float per_r, float time_r, float per_g, float time_g, |
PET | 0:c426396d5fdf | 40 | float per_b, float time_b) |
PET | 0:c426396d5fdf | 41 | { |
PET | 0:c426396d5fdf | 42 | pin_r.period(per_r); // Sets the period in seconds of the LED. |
PET | 0:c426396d5fdf | 43 | pin_r.write(time_r); // The %age of the period that the LED is turned on. |
PET | 0:c426396d5fdf | 44 | pin_g.period(per_g); |
PET | 0:c426396d5fdf | 45 | pin_g.write(time_g); |
PET | 0:c426396d5fdf | 46 | pin_b.period(per_b); |
PET | 0:c426396d5fdf | 47 | pin_b.write(time_b); |
PET | 0:c426396d5fdf | 48 | } |