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: max32630fthr Adafruit_FeatherOLED USBDevice
LEDStatus.h
00001 /******************************************************************************* 00002 * Author: Shaun Kelsey, shaun.kelsey@maximintegrated.com 00003 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a 00006 * copy of this software and associated documentation files (the "Software"), 00007 * to deal in the Software without restriction, including without limitation 00008 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00009 * and/or sell copies of the Software, and to permit persons to whom the 00010 * Software is furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included 00013 * in all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00016 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00017 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00018 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00019 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00020 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00021 * OTHER DEALINGS IN THE SOFTWARE. 00022 * 00023 * Except as contained in this notice, the name of Maxim Integrated 00024 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00025 * Products, Inc. Branding Policy. 00026 * 00027 * The mere transfer of this software does not imply any licenses 00028 * of trade secrets, proprietary technology, copyrights, patents, 00029 * trademarks, maskwork rights, or any other form of intellectual 00030 * property whatsoever. Maxim Integrated Products, Inc. retains all 00031 * ownership rights. 00032 ******************************************************************************* 00033 */ 00034 00035 #ifndef _LEDSTATUS_H_ 00036 #define _LEDSTATUS_H_ 00037 #include "mbed.h" 00038 00039 class LEDStatus 00040 { 00041 public: 00042 00043 /** Create an LED_Status controller 00044 * 00045 * @param red PinName of red LED 00046 * @param rstate Initial state of red LED 00047 * @param green PinName of green LED 00048 * @param gstate Initial state of green LED 00049 * @param blue PinName of blue LED 00050 * @param bstate Initial state of blue LED 00051 */ 00052 LEDStatus(PinName red, int rstate, PinName green, int gstate, PinName blue, int bstate); 00053 00054 /** Set the active state of each LED 00055 * 00056 * @param rstate active state of red LED 00057 * @param gstate active state of green LED 00058 * @param bstate active state of blue LED 00059 */ 00060 void set_state(int rstate, int gstate, int bstate); 00061 00062 /** Set and keep the LEDs in their active state */ 00063 void solid(); 00064 00065 /** Set the LEDs to toggle between their active state and their off state 00066 * 00067 * @param ontime The amount of time (in milliseconds) to remain in the active state 00068 * @param offtime The amount of time (in milliseconds) to remain off 00069 * @param nb The number of times to blink before remaining in the off state 00070 * Set to -1 to blink indefinitely 00071 * 00072 */ 00073 void blink(int ontime, int offtime, int nb = -1); 00074 00075 /** Set the LEDs to toggle between their active state and their off state 00076 * 00077 * @param period The period of each blink (in milliseconds) 00078 * @param offtime The percentage of the period during which the LEDs will be in their active state 00079 * @param nb The number of times to blink before remaining in the off state 00080 * Set to -1 to blink indefinitely 00081 */ 00082 void blink(int period, float duty, int nb = -1); 00083 00084 /** Get whether LEDState is in the blinking state 00085 */ 00086 bool is_blinking(); 00087 00088 /** Called in main loop of program to advance the state of the class 00089 * @detail Instead of using a Ticker and generating additional interrupts and overhead, 00090 * LEDStatus relies on update being called at a decent interval in order 00091 * to advance its interval time keeping and blink LEDs and the correct rate. 00092 * If only using solid() mode, update() does not need to be called. 00093 */ 00094 void update(); 00095 00096 private: 00097 00098 DigitalOut rLED; 00099 DigitalOut gLED; 00100 DigitalOut bLED; 00101 00102 int r_act; 00103 int g_act; 00104 int b_act; 00105 00106 bool blinking; 00107 bool bs; 00108 int count; 00109 int total; 00110 00111 uint64_t ont_us; 00112 uint64_t offt_us; 00113 00114 Timer timer; 00115 00116 }; 00117 00118 #endif 00119
Generated on Tue Jul 12 2022 20:09:28 by
