class Arc { // created a class for the concept of an "arc". In this case the tracing pattern
public:
Arc(int, int, int); // what properties and behaviors make up an "arc" and separate them from each other. The constructor
void flash(int duration, int intensity, int flashCount); //
void fade(int duration);
void flashWithFade(int duration, int intensity, int flashCount);
private:
int led0, led1, led2;
void flashOnce(int, int, int);
};
Arc::Arc(int led0, int led1, int led2) { // in this project, and arc has 3 LEDS
this->led0 = led0;
this->led1 = led1;
this->led2 = led2;
}
void overlapFlash0();
void overlapFlash1();
void overlapFlash2();
void Arc::fade(int duration) {
analogWrite(this->led0, 255);
delay(duration);
analogWrite(this->led1, 255);
delay(duration);
analogWrite(this->led2, 255);
delay(duration);
for(int ledVal = 255; ledVal >= 0; ledVal--) {
analogWrite(this->led0, ledVal);
analogWrite(this->led1, ledVal);
analogWrite(this->led2, ledVal);
delay(5);
}
}
void Arc::flashOnce(int led, int duration, int intensity) {
analogWrite(led, intensity);
delay(duration);
}
void Arc::flash(int duration, int intensity, int flashCount) {
for (int i = 1; i <= flashCount; i++) {
this->flashOnce(led0, duration, intensity);
this->flashOnce(led1, duration, intensity);
this->flashOnce(led2, duration, intensity);
this->flashOnce(led0, duration, 0);
this->flashOnce(led1, duration, 0);
this->flashOnce(led2, duration, 0);
}
}
void Arc::flashWithFade(int duration, int intensity, int flashCount) {
this->flash(duration, intensity, flashCount - 1);
this->fade(duration);
}
class Led {
public:
Led(int led);
void fade(int duration);
void flash(int duration, int intensity, int flashCount);
void setAndDelay(int intensity, int delayTime);
void flashPattern0();
void flashPattern1();
void flashPattern2();
void flashPattern3();
void flashPattern4();
void flashPattern5();
void overlapFlash0();
void overlapFlash1();
void overlapFlash2();
private:
int led;
};
Led::Led (int led) {
this->led = led;
}
void Led::setAndDelay(int intensity, int delayTime) {
analogWrite(this->led, intensity);
delay(delayTime);
}
void Led::flash(int duration, int intensity, int flashCount) {
for (int i = 1; i <= flashCount; i++) {
this->setAndDelay(duration, intensity);
this->setAndDelay(duration, 0);
}
}
void Led::fade(int duration) {
for(int ledVal = 255; ledVal >= 0; ledVal--) {
this->setAndDelay(ledVal, duration);
}
}
/*********************************************
*
* Main code block
*
********************************************/
/// Bolt 1
const int ARC_0_LED_0 = 3;
const int ARC_0_LED_1 = 5;
const int ARC_0_LED_2 = 6;
/// Bolt 2
const int ARC_1_LED_0 = 9;
const int ARC_1_LED_1 = 10;
const int ARC_1_LED_2 = 11; /// includes tentacle
// Lighthouse
const int LIGHTHOUSE_LED = A0;
//Cabin
const int CABIN_LED = A1;
// Arc references
const Arc arc0(ARC_0_LED_0, ARC_0_LED_1, ARC_0_LED_2);
const Arc arc1(ARC_1_LED_0, ARC_1_LED_1, ARC_1_LED_2);
// Led references
const Led arc0_led0(ARC_0_LED_0);
const Led arc0_led1(ARC_0_LED_1);
const Led arc0_led2(ARC_0_LED_2);
const Led arc1_led0(ARC_1_LED_0);
const Led arc1_led1(ARC_1_LED_1);
const Led arc1_led2(ARC_1_LED_2);
void setup() {
pinMode(ARC_0_LED_0, OUTPUT); //set pins to output
pinMode(ARC_0_LED_1, OUTPUT);
pinMode(ARC_0_LED_2, OUTPUT);
pinMode(ARC_1_LED_0, OUTPUT);
pinMode(ARC_1_LED_1, OUTPUT);
pinMode(ARC_1_LED_2, OUTPUT);
pinMode(LIGHTHOUSE_LED, OUTPUT);
pinMode(CABIN_LED, OUTPUT);
}
/*********************************************
*
* What matters now
*
********************************************/
void loop() {
digitalWrite(LIGHTHOUSE_LED, HIGH);
digitalWrite(CABIN_LED, HIGH);
overlapFlash0();
delay(20);
arc0.flashWithFade(40, 100, 3); //duration, intensity, count
delay(100);
arc1_led0.flashPattern5();
delay(50);
arc0_led1.flashPattern2();
delay(1000);
arc1.flashWithFade(50,100,2);
delay(1000);
arc1_led2.flashPattern2();
delay(1000);
overlapFlash1();
delay(20);
arc1_led1.flashPattern3();
delay(100);
arc0_led2.flashPattern0();
delay(1000);
arc1.flashWithFade(50,255,4);
delay(100);
arc0_led0.flashPattern2();
delay(0);
arc1_led1.flashPattern3();
delay(20);
arc0.flashWithFade(20,255,1);
delay(100);
arc1_led2.flashPattern1();
delay(0);
arc1_led0.flashPattern2();
delay(0);
arc0_led2.flashPattern2();
delay(2000);
}
// Single point flash patterns
void Led::flashPattern0()
{
this->setAndDelay(255, 50);
this->setAndDelay(0, 10);
this->setAndDelay(50, 100);
this->setAndDelay(0, 50);
this->setAndDelay(255, 5);
this->fade(4);
}
void Led::flashPattern1()
{
this->setAndDelay(50, 20);
this->setAndDelay(100, 100);
this->setAndDelay(0, 125);
this->setAndDelay(200, 50);
this->setAndDelay(0, 18);
this->setAndDelay(255, 5);
this->fade(4);
}
void Led::flashPattern2()
{
this->setAndDelay(30, 10);
this->setAndDelay(100, 50);
this->setAndDelay(0, 125);
this->setAndDelay(255, 150);
this->fade(4);
}
void Led::flashPattern3()
{
this->setAndDelay(50, 10);
this->setAndDelay(100, 30);
this->setAndDelay(0, 50);
this->setAndDelay(150, 40);
this->setAndDelay(0, 18);
this->setAndDelay(30, 30);
this->setAndDelay(0, 45);
this->setAndDelay(50, 80);
this->setAndDelay(0, 18);
this->setAndDelay(150, 40);
this->setAndDelay(0, 18);
this->setAndDelay(30, 30);
this->setAndDelay(0, 45);
this->setAndDelay(50, 80);
this->setAndDelay(0, 18);
this->setAndDelay(255, 100);
this->setAndDelay(0, 18);
this->fade(5);
}
void Led::flashPattern4()
{
this->setAndDelay(50, 10);
this->setAndDelay(15, 100);
this->setAndDelay(0, 125);
this->setAndDelay(25, 150);
this->setAndDelay(0, 18);
this->setAndDelay(10, 30);
this->setAndDelay(0, 80);
this->setAndDelay(40, 50);
this->setAndDelay(0, 30);
this->fade(4);
}
void Led::flashPattern5()
{
this->setAndDelay(255, 10);
this->setAndDelay(0, 100);
this->setAndDelay(100, 100);
this->setAndDelay(255, 125);
this->setAndDelay(0, 100);
this->setAndDelay(100, 100);
this->setAndDelay(255, 125);
this->setAndDelay(0, 50);
this->setAndDelay(200, 80);
this->setAndDelay(255, 60);
this->fade(4);
}
void overlapFlash0()
{
arc0_led2.setAndDelay(255, 10);
arc0_led2.setAndDelay(0, 100);
arc0_led2.setAndDelay(100, 100);
arc0_led2.setAndDelay(255, 125);
arc0_led2.setAndDelay(0, 100);
arc1_led0.setAndDelay(255, 10);
arc0_led2.setAndDelay(100, 100);
arc1_led0.setAndDelay(0, 100);
arc0_led2.setAndDelay(255, 125);
arc1_led0.setAndDelay(100, 100);
arc0_led2.setAndDelay(0, 50);
arc1_led0.setAndDelay(255, 125);
arc0_led2.setAndDelay(200, 80);
arc1_led0.setAndDelay(0, 100);
arc0_led2.setAndDelay(255, 60);
arc1_led0.setAndDelay(100, 100);
arc0_led2.fade(4);
arc1_led0.setAndDelay(255, 125);
arc1_led0.setAndDelay(0, 50);
arc1_led0.setAndDelay(200, 80);
arc1_led0.setAndDelay(255, 60);
arc1_led0.fade(4);
}
void overlapFlash1()
{
arc0_led0.setAndDelay(255, 10);
arc0_led0.setAndDelay(0, 100);
arc0_led0.setAndDelay(100, 100);
arc0_led0.setAndDelay(255, 125);
arc0_led0.setAndDelay(0, 100);
arc1_led1.setAndDelay(255, 10);
arc0_led0.setAndDelay(100, 100);
arc1_led1.setAndDelay(0, 100);
arc0_led0.setAndDelay(255, 125);
arc1_led1.setAndDelay(100, 100);
arc0_led0.setAndDelay(0, 50);
arc1_led1.setAndDelay(255, 125);
arc0_led0.setAndDelay(200, 80);
arc1_led1.setAndDelay(0, 100);
arc0_led0.setAndDelay(255, 60);
arc1_led1.setAndDelay(100, 100);
arc0_led0.fade(4);
arc1_led1.setAndDelay(255, 125);
arc1_led1.setAndDelay(0, 50);
arc1_led1.setAndDelay(200, 80);
arc1_led1.setAndDelay(255, 60);
arc1_led1.fade(4);
}
void Led::overlapFlash2()
{
this->setAndDelay(255, 10);
this->setAndDelay(0, 100);
this->setAndDelay(100, 100);
this->setAndDelay(255, 125);
this->setAndDelay(0, 100);
this->setAndDelay(100, 100);
this->setAndDelay(255, 125);
this->setAndDelay(0, 50);
this->setAndDelay(200, 80);
this->setAndDelay(255, 60);
this->fade(4);
}