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.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 /******************** 00004 * Interactive Device Design Custom Class Demonstration 00005 * bjoern@eecs.berkeley.edu, 9/23/2015 00006 ********************/ 00007 00008 00009 class RGBLed { 00010 public: 00011 00012 // constructor - same name as class, does nothing 00013 RGBLed () { 00014 } 00015 00016 //set red, green, blue of on-board LED 00017 // r,g,b range from 0.0(off) to 1.0(full on) 00018 void setColor(float r, float g, float b){ 00019 PwmOut redPin(LED_RED); 00020 PwmOut greenPin(LED_GREEN); 00021 PwmOut bluePin(LED_BLUE); 00022 redPin = 1.0-r; //invert: PWM 0=on, 1.0=off 00023 bluePin = 1.0-b; 00024 greenPin = 1.0-g; 00025 } 00026 private: 00027 //no private methods or fields 00028 }; 00029 00030 00031 RGBLed myLed; //declare a variable of our new class type 00032 00033 int main() { 00034 while(1) { 00035 myLed.setColor(1.0, 0.0, 0.0); //call the member function setColor() - this is red 00036 wait(0.2); 00037 myLed.setColor(0.0, 1.0, 0.0); //this is green 00038 wait(0.2); 00039 } 00040 }
Generated on Wed Jul 20 2022 08:50:53 by
1.7.2