PRO2_Team 1_collected code with ticker and headers_not working yet

Dependencies:   SHTx mbed

Fork of PRO2_samlet_kode by Olga Høyer

rgb_led.cpp

Committer:
OlgaHoeyer
Date:
2017-06-20
Revision:
11:3ff48fb0aa0b
Parent:
7:75d5c1db2027

File content as of revision 11:3ff48fb0aa0b:

/*
--------------------------------------------------------------------------------
-- 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 period, float on_timer)
{
    pin_r.period(period);   // Sets the period in seconds of the LED.
    pin_r.write(on_timer);  // The %age of the period that the LED is turned on.
    pin_g.period(period);
    pin_g.write(on_timer);
    pin_b.period(period);
    pin_b.write(on_timer);
}