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
Diff: rgb_led.cpp
- Revision:
- 0:c426396d5fdf
diff -r 000000000000 -r c426396d5fdf rgb_led.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rgb_led.cpp Thu Jun 22 04:45:01 2017 +0000 @@ -0,0 +1,48 @@ +/* +-------------------------------------------------------------------------------- +-- Project: PRO2 "Awareness and Optimisation of energy consumption" +-- Team: Team 1 + +-- File Name: rgb_led.cpp +-- Author: Poul Erik Tjørnfelt +-- Date: 07/05-2017 +-- Copyright: Open to all +-- Version: 0.6 - Creation of file. +-- 1.0 - Finished version. +-- +-- Description: The .cpp file for a class, that creates instances of +-- the actual RGB lamp that is used. +-- +-- +-------------------------------------------------------------------------------- +*/ + +#include "mbed.h" +#include "rgb_led.h" + +RGB_LED::RGB_LED(PinName pin_R, PinName pin_G, PinName pin_B) + :pin_r(pin_R), pin_g(pin_G), pin_b(pin_B) // Constructor +{ + +} + +void RGB_LED::set(float red,float green, float blue) +{ + pin_r = red; // The amount of the single colours that we want in the + pin_g = green; // actual colour (ex. purple = 0.7f, 0.0, 0.7f), gotten from + pin_b = blue; // www.w3schools.com/colors/colors_picker.asp. + /* + We only use red, orange (2 parts red, 1 part green), green and blue. + */ +} + +void RGB_LED::flash(float per_r, float time_r, float per_g, float time_g, + float per_b, float time_b) +{ + pin_r.period(per_r); // Sets the period in seconds of the LED. + pin_r.write(time_r); // The %age of the period that the LED is turned on. + pin_g.period(per_g); + pin_g.write(time_g); + pin_b.period(per_b); + pin_b.write(time_b); +} \ No newline at end of file