Initial commit
This commit is contained in:
commit
f1389eda5d
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
ESP8266 BlinkWithoutDelay by Simon Peter
|
||||
Blink the blue LED on the ESP-01 module
|
||||
Based on the Arduino Blink without Delay example
|
||||
This example code is in the public domain
|
||||
|
||||
The blue LED on the ESP-01 module is connected to GPIO1
|
||||
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
|
||||
|
||||
Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
|
||||
*/
|
||||
|
||||
class RgbLed {
|
||||
int ledRedPin;
|
||||
int ledGreenPin;
|
||||
int ledBluePin;
|
||||
|
||||
byte ledRedIntensity;
|
||||
byte ledGreenIntensity;
|
||||
byte ledBlueIntensity;
|
||||
|
||||
byte ledRedIntensityTo;
|
||||
byte ledGreenIntensityTo;
|
||||
byte ledBlueIntensityTo;
|
||||
|
||||
long durationLeft;
|
||||
long currentMillis;
|
||||
|
||||
public:
|
||||
RgbLed(int redPin, int greenPin, int bluePin)
|
||||
{
|
||||
ledRedPin = redPin;
|
||||
ledGreenPin = greenPin;
|
||||
ledBluePin = bluePin;
|
||||
|
||||
pinMode(ledRedPin, OUTPUT);
|
||||
pinMode(ledGreenPin, OUTPUT);
|
||||
pinMode(ledBluePin, OUTPUT);
|
||||
|
||||
ledRedIntensity = 0;
|
||||
ledGreenIntensity = 0;
|
||||
ledBlueIntensity = 0;
|
||||
|
||||
ledRedIntensityTo = ledRedIntensity;
|
||||
ledGreenIntensityTo = ledGreenIntensity;
|
||||
ledBlueIntensityTo = ledBlueIntensity;
|
||||
|
||||
durationLeft = 0;
|
||||
currentMillis = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
void ChangeColor(int redIntesity, int greenIntensity, int blueIntensity, long duration)
|
||||
{
|
||||
if (ledRedIntensityTo == ledRedIntensity && ledGreenIntensityTo == ledGreenIntensity && ledBlueIntensityTo == ledBlueIntensity
|
||||
&& ledRedIntensity != redIntesity && ledGreenIntensity != greenIntensity && ledBlueIntensity != blueIntensity) {
|
||||
durationLeft = duration;
|
||||
ledRedIntensityTo = ledRedIntensity;
|
||||
ledGreenIntensityTo = ledGreenIntensity;
|
||||
ledBlueIntensityTo = ledBlueIntensity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
void Update(long currentMillis)
|
||||
{
|
||||
// if(currentMillis - this->currentMillis >= interval) {
|
||||
// this->currentMillis = currentMillis;
|
||||
// digitalWrite(led, intensity);
|
||||
// }
|
||||
// if (ledRedIntensityTo != ledRedIntensity && ledGreenIntensityTo != ledGreenIntensity && ledBlueIntensityTo != ledBlueIntensity) {
|
||||
// ledRedIntensity = ;
|
||||
// ledGreenIntensity = ;
|
||||
// ledBlueIntensity = ;
|
||||
// }
|
||||
}
|
||||
|
||||
byte lerp(byte from, byte to, long t) {
|
||||
return from + t * (to - from);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
RgbLed ledStripe(5, 4, 0);
|
||||
|
||||
void setup() {
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ledStripe.ChangeColor(30, 200, 255, 1000);
|
||||
ledStripe.Update(millis());
|
||||
}
|
||||
|
||||
|
||||
//void led_blink(int led, byte intensity, long interval) {
|
||||
// unsigned long currentMillis = millis();
|
||||
// if(currentMillis - previousMillis >= interval) {
|
||||
// previousMillis = currentMillis;
|
||||
// digitalWrite(led, intensity);
|
||||
// }
|
||||
//}
|
Loading…
Reference in New Issue