/* A Witch's Atelier final code. Fab Academy 2024 Final Project. Siddharth Agarwal. This code was written by Siddharth Agarwal, June 2024. This work may be reproduced, modified, distributed, performed, and displayed for any purpose, but must acknowledge this project. Copyright is retained and must be preserved. The work is provided as is; no warranty is provided, and users accept all liability. */ // #include // Servo myservo; int pos = 0; int cauldron = D4; int castle = D5; int camp = D7; int mortar = D6; // const int buttonPin = D8; // int buttonState = 0; void setup() { pinMode(camp, OUTPUT); pinMode(cauldron, OUTPUT); pinMode(mortar, OUTPUT); pinMode(castle, OUTPUT); // pinMode(buttonPin, INPUT); // myservo.attach(D9); } void loop() { //The lightning of the castle runs after every other tile. //Castle Lightning > Camp fire > Castle Lightning > Cauldron Fire > Castle Lightning > Mortar Pulse > Castle Lightning > Castle Flicker castle1(); camp1(); castle1(); cauldron1(); castle1(); mortar1(); castle1(); castle2(); //Code for reed switch and servo trigger: // buttonState = digitalRead(buttonPin); // Serial.println(buttonState); // if (buttonState == HIGH) { // for (pos = 0; pos <= 180; pos += 1) { // myservo.write(pos); // delay(15); // } // } // if (buttonState == LOW){ // for (pos = 180; pos >= 0; pos -= 1) { // myservo.write(pos); // delay(15); // } // } } void camp1() { for (int fadeValue = 0; fadeValue <= 255; fadeValue += 1) { //camp fade in: analogWrite(camp, fadeValue); delay(1);} for (int i = 0; i <= 100; i++) { //camp flicker analogWrite(camp, random(120) + 135); delay(random(100)); } for (int fadeValue = 255; fadeValue >= 0; fadeValue--) { //camp fade out: analogWrite(camp, fadeValue); delay(1); } } void cauldron1() { int i = 0; for (int fadeValue = 0; fadeValue <= 255; fadeValue += 1) { //cauldron fade in: analogWrite(cauldron, fadeValue); delay(1); } for (int fadeValue = 255; fadeValue >= 0; fadeValue--) { analogWrite(cauldron, fadeValue); delay(2); } for (i = 0; i <= 100; i++) { //cauldron flame: Serial.println(i); analogWrite(cauldron, random(120) + 135); delay(random(100)); } for (int fadeValue = 255; fadeValue >= 0; fadeValue--) { //cauldron fade out: analogWrite(cauldron, fadeValue); delay(7); } } void mortar1() { for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5) { //mortar fade in analogWrite(mortar, fadeValue); delay(100); } for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) { //mortar fade out analogWrite(mortar, fadeValue); delay(100); } delay(2000); } void castle1() { //lightning pulse 1 analogWrite(castle, 255); delay(100); analogWrite(castle, 0); delay(50); //lightning pulse 2 analogWrite(castle, 255); delay(50); for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) { //fade out analogWrite(castle, fadeValue); delay(10); } analogWrite(castle, 0); delay(500); } void castle2() { //Flickering of the castle after few rounds of the lightning for (int fadeValue = 0; fadeValue <= 255; fadeValue++) { analogWrite(castle, fadeValue + random(-100, 100)); delay(10); } analogWrite(castle, 255); delay(5000); analogWrite(castle, 0); }