Created
December 17, 2019 04:50
-
-
Save BaReinhard/e826e61542a0ac32808893c1333edb55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Program: RGB Color Change | |
//Programmer: Brett Reinhard | |
//Date: 10/20/2016 | |
//Description: Changes color of LED's within the Pumpkin, with smooth transitions. | |
int const Red = 9, /* Pin 3 */ Blue = 11, /* Pin 5 */ Green = 10; /* Pin 6 */ | |
class Pumpkin | |
{ | |
private: | |
int *_r; | |
int *_g; | |
int *_b; | |
bool flash; | |
public: | |
Pumpkin() | |
{ | |
*_r = new int(); | |
*_g = new int(); | |
*_b = new int(); | |
_flash = false; | |
} | |
void Start() | |
{ | |
if (_flash) | |
{ | |
*_r = 255; | |
*_g = 0; | |
*_b = 0; | |
for (int i = 0; i < 256; ++i) | |
{ | |
int rand = random(0, 9); | |
if (rand == 0 || rand == 1 || rand == 3) | |
{ | |
RGB(0, 0, 0); | |
delay(25); | |
*_g = i; | |
RGB(); | |
} | |
else | |
{ | |
*_g = i; | |
RGB(); | |
} | |
} | |
*_r = 255; | |
*_g = 255; | |
*_b = 0; | |
for (int i = 255; i >= 0; --i) | |
{ | |
int rand = random(0, 9); | |
if (rand == 0 || rand == 1 || rand == 3) | |
{ | |
RGB(0, 0, 0); | |
delay(25); | |
*_r = i; | |
RGB(); | |
} | |
else | |
{ | |
*_r = i; | |
RGB(); | |
} | |
} | |
*_r = 0; | |
*_g = 255; | |
*_b = 0; | |
for (int i = 0; i < 256; ++i) | |
{ | |
int rand = random(0, 9); | |
if (rand == 0 || rand == 1 || rand == 3) | |
{ | |
RGB(0, 0, 0); | |
delay(25); | |
*_b = i; | |
RGB(); | |
} | |
else | |
{ | |
*_b = i; | |
RGB(); | |
} | |
} | |
*_r = 0; | |
*_g = 255; | |
*_b = 255; | |
for (int i = 255; i >= 0; --i) | |
{ | |
int rand = random(0, 9); | |
if (rand == 0 || rand == 1 || rand == 3) | |
{ | |
off(0, 0, 0); | |
delay(25); | |
*_g = i; | |
RGB(); | |
} | |
else | |
{ | |
*_g = i; | |
RGB(); | |
} | |
} | |
*_r = 0; | |
*_g = 0; | |
*_b = 255; | |
for (int i = 0; i < 256; ++i) | |
{ | |
int rand = random(0, 9); | |
if (rand == 0 || rand == 1 || rand == 3) | |
{ | |
RGB(0, 0, 0); | |
delay(25); | |
*_r = i; | |
RGB() | |
} | |
else | |
{ | |
*_r = i; | |
RGB()); | |
} | |
} | |
*_r = 255; | |
*_g = 0; | |
*_b = 255; | |
for (int i = 255; i >= 0; --i) | |
{ | |
int rand = random(0, 9); | |
if (rand == 0 || rand == 1 || rand == 3) | |
{ | |
RGB(0, 0, 0); | |
delay(25); | |
*_b = i; | |
RGB(); | |
} | |
else | |
{ | |
*_b = i; | |
RGB(); | |
} | |
} | |
delay(1000); | |
this->Start(); | |
} | |
else | |
{ | |
*_r = 255; | |
*_g = 0; | |
*_b = 0; | |
for (int i = 0; i < 256; ++i) | |
{ | |
*_g = i; | |
RGB(); | |
} | |
*_r = 255; | |
*_g = 255; | |
*_b = 0; | |
for (int i = 255; i >= 0; --i) | |
{ | |
*_r = i; | |
RGB(); | |
} | |
*_r = 0; | |
*_g = 255; | |
*_b = 0; | |
for (int i = 0; i < 256; ++i) | |
{ | |
*_b = i; | |
RGB(); | |
} | |
*_r = 0; | |
*_g = 255; | |
*_b = 255; | |
for (int i = 255; i >= 0; --i) | |
{ | |
*_g = i; | |
RGB(); | |
} | |
*_r = 0; | |
*_g = 0; | |
*_b = 255; | |
for (int i = 0; i < 256; ++i) | |
{ | |
*_r = i; | |
RGB(); | |
} | |
*_r = 255; | |
*_g = 0; | |
*_b = 255; | |
for (int i = 255; i >= 0; --i) | |
{ | |
*_g = i; | |
RGB() | |
} | |
delay(1000); | |
this->Start(); | |
} | |
} | |
void RBG(int r, int g, int b) | |
{ | |
analogWrite(Red, r); | |
analogWrite(Green, g); | |
analogWrite(Blue, b); | |
delay(25); | |
} | |
void RGB() | |
{ | |
analogWrite(Red, *_r); | |
analogWrite(Green, *_g); | |
analogWrite(Blue, *_b); | |
delay(25); | |
} | |
void Flash(bool flash) | |
{ | |
_flash = flash; | |
} | |
~Pumpkin() | |
{ | |
delete _r; | |
delete _g; | |
delete _b; | |
} | |
}; | |
void setup() | |
{ | |
Pumpkin pump(0, 0, 0); | |
pump.Flash(true); | |
pump.Start(); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment