2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
LED.h
Go to the documentation of this file.
1
4
25
26#pragma once
27
28#include <Arduino.h>
29
30#include "MiscConstants.h"
31
32constexpr unsigned BLINK_FAST_PERIOD_MS = 500;
33constexpr unsigned BLINK_SLOW_PERIOD_MS = 1000;
34constexpr unsigned PULSE_FAST_PERIOD_MS = 250;
35constexpr unsigned PULSE_SLOW_PERIOD_MS = 500;
36
37constexpr unsigned char PWM_MIN_BRIGHTNESS = 64;
38constexpr unsigned char PWM_MAX_BRIGHTNESS = 255;
39
40constexpr unsigned PERIODDIVISOR = 16;
41
42class LED {
43 public:
44 enum class LEDPattern {
45 SOLID = 0,
50 };
51
52 explicit LED(uint8_t controlPin);
53 LED(uint8_t controlPin, bool pwmEnable);
54 LED(uint8_t controlPin, uint8_t groundPin, bool pwmEnable = false);
55
56 void Initialize();
57 void Update();
58
59 void On();
60 void Off();
61
62 bool GetIlluminated() const;
63
64 void SetPattern(LEDPattern newPattern);
65 LEDPattern GetPattern() const;
66
67 bool IsPWM() const;
68
69 private:
70 const uint8_t m_controlPin;
71 const uint8_t m_groundPin;
72 const bool m_pwmEnable;
73
77
78 static uint8_t GAMMA[256];
79 static bool GAMMA_INITIALIZED;
80
81 void SetPulse();
82 void SetFlash();
83 void SetSolid();
84
85 uint8_t CalcPulseBrightness(uint8_t brightness, uint16_t period, bool smooth = false, uint8_t offBrightness = 0);
86};
constexpr unsigned char PWM_MAX_BRIGHTNESS
Definition LED.h:38
constexpr unsigned PERIODDIVISOR
Definition LED.h:40
constexpr unsigned BLINK_SLOW_PERIOD_MS
Definition LED.h:33
constexpr unsigned char PWM_MIN_BRIGHTNESS
Definition LED.h:37
constexpr unsigned BLINK_FAST_PERIOD_MS
Definition LED.h:32
constexpr unsigned PULSE_FAST_PERIOD_MS
Definition LED.h:34
constexpr unsigned PULSE_SLOW_PERIOD_MS
Definition LED.h:35
Miscellaneous constants for the operator controller.
Definition LED.h:42
static bool GAMMA_INITIALIZED
Definition LED.h:79
void Initialize()
Definition LED.cpp:60
bool IsPWM() const
Definition LED.cpp:113
void SetPattern(LEDPattern newPattern)
Definition LED.cpp:105
uint8_t CalcPulseBrightness(uint8_t brightness, uint16_t period, bool smooth=false, uint8_t offBrightness=0)
Definition LED.cpp:177
LEDPattern
Definition LED.h:44
void On()
Definition LED.cpp:91
static uint8_t GAMMA[256]
Definition LED.h:78
bool GetIlluminated() const
Definition LED.cpp:101
LEDPattern m_pattern
Definition LED.h:75
const uint8_t m_controlPin
Definition LED.h:70
void SetPulse()
Definition LED.cpp:117
const uint8_t m_groundPin
Definition LED.h:71
bool m_illuminate
Definition LED.h:76
void Off()
Definition LED.cpp:96
void Update()
Definition LED.cpp:74
void SetFlash()
Definition LED.cpp:147
bool m_initialized
Definition LED.h:74
const bool m_pwmEnable
Definition LED.h:72
void SetSolid()
Definition LED.cpp:171
LEDPattern GetPattern() const
Definition LED.cpp:109