Rank: Amateur level 2 Groups: Registered
Joined: 15/03/2017 Posts: 46 Points: 138 Location: Outer reaches of the galaxy .... West Midlands
|
Code Within:
Code: //#define BLYNK_DEBUG // Optional, this enables lots of prints //#define BLYNK_PRINT Serial
// // DeAGOSTINI Millennium Falcon Light & Sound Control V3.0 // // for Arduino Mega/Mega2560
#include <BlynkSimpleShieldEsp8266.h> #include <SoftwareSerial.h> #include <DFPlayer_Mini_Mp3.h> #include <DFRobotDFPlayerMini.h> #include <FastLED.h>
BlynkTimer timer;
#define Ready_LED 51 #define NoMusicFiles 14 #define RandomLEDs 4 // Length of flash LED data Array #define StartPIN 28 // LED Pin 28 - 33 #define LED_Red "#D3435C" #define LED_Green "#23C48E"
WidgetTerminal terminal(V0); WidgetLED RampLEDup(V3); WidgetLED RampLEDdown(V4); WidgetLED Rdy1LED(V17); WidgetLED Rdy2LED(V18); WidgetLED Rdy3LED(V19); WidgetLED Rdy4LED(V20);
char auth[] = "blynk auto code"; char ssid[] = "Your SSID"; char pass[] = "Password";
#define ESP8266_Serial Serial3 // Hardware Serial to ESP8266 long int ESP8266_BAUD = 115200; ESP8266 wifi(&ESP8266_Serial);
//--- DC Motor --------------------------------------------------- const int buttonON = LOW; // When the button is pressed, the value of the pin is LOW const int buttonOFF = HIGH; // When the button is pressed, the value of the pin is HIGH const int DC_1A = 5; // DC motor 1 pin A const int DC_1B = 6; // DC motor 1 pin B const int SW_1A = 7; // DC motor 1 stop switch 1 pin 1 const int SW_1B = 8; // DC motor 1 stop switch 1 pin 2 int DC_RO = 0; // DC motor 1 rotation direction boolean DC_state1; // DC motor 1 stop switch 1 boolean DC_state2; // DC motor 1 stop switch 2 boolean EngineRunFlag; // Engines running flag boolean HyperdriveFlag; // Hyperdrive engaged flag boolean RdyFlag = true; boolean rampdownflag = false; boolean rampupflag = false; boolean cannonFlag = false; boolean chatterFlag = false; boolean audioflag = false;
const int NeopixelPin = 9; // the number of the neopixel strips pin const int NUMPIXELS = 45; // Number of pixels in the strip CRGB LED_Array[NUMPIXELS];
// -------------------------------------------- DATA ARRAYS ------------------------------------------------------ // // REFERENCE: 0 1 2 3 // PIN: 28 29 30 31 boolean SW_LED[RandomLEDs] = { 0, 0, 0, 0}; // LED lighting switch int SW_VAL1[RandomLEDs] = {300, 200, 100, 5}; // LED lighting time (0: constant light) int SW_VAL2[RandomLEDs] = {300, 200, 100, 1}; // LED off time int SW_RAN1[RandomLEDs] = { 30, 30, 30, 3}; // LED random lighting time int SW_RAN2[RandomLEDs] = { 30, 30, 30, 5}; // LED random turn off time int SW_On[RandomLEDs] = {}; // LED ON (0: OFF while 1: ON) int SW_CNT[RandomLEDs] = {}; // LED counter int MusicID[NoMusicFiles] = {0, 1, 2, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46}; String MusicName[NoMusicFiles] = {"", "Main Title - The Ice Planet Hoth", "ANH - The Throne Room", "The Imperial March", "Across The Stars", "Duel Of The Fates", "The Falcon", "Bounty Hunters Pursuit", "Mos Eisley Spaceport", "Cantina Band", "City In The Clouds", "Emperors Throne Room", "I Can Fly Anything", "Battle Of The Heroes"};
// -- MP3 Variables ---------------------------------------------------------------------------------------- DFRobotDFPlayerMini myDFPlayer; #define Busy_PIN 2 //Busy PIN #define MP3_CFolder 240 //Folder specification command #define MP3_CPlay 236 //Play command #define MP3_CStop 239 //Stop command #define MP3_CVol 200 //Volume command int MP3_Folder = 1; //MP3 folder int MP3_No = 1; //MP3 audio number int MP3_Vol = 15; //MP3 volume int GunVoice = 0; //Laser cannon int TrVoice = 0; //Luke training int EnVoice = 0; //Engine startup int MusicST = 0; //Music playback
int pinValueV1 = 0; int pinValueV2 = 0; int pinValueV3 = 0; int pinValueV6 = 0; int pinValueV7 = 0; int pinValueV8 = 0; int pinValueV9 = 0; int pinValueV10 = 0; int pinValueV11 = 0; int pinValueV12 = 0; int pinValueV13 = 0; int pinValueV14 = 0; int pinValueV15 = 0; int pinValueV16 = 0; int pinValueV17 = 0; int pinValueV18 = 0;
int PixelRan1 = 0; int PixelRan2 = 0; int PixelRan3 = 0; int PixelRan4 = 0; int PixelRan5 = 0; int PrevPixelRan1 = 20; int PrevPixelRan2 = 20; int PrevPixelRan3 = 20; int PrevPixelRan4 = 20; int PrevPixelRan5 = 20;
int randomChatter; int cannonCount = 0; int rampTimer; int hyperdriveTimer; int cannonTimer; int chatterTimer; bool initialisationpass = true;
// ------------------------------------------------------------------------------------------------------------ // // ------------------------------------------ Blynk Widget Sub-routines --------------------------------------- // // ------------------------------------------------------------------------------------------------------------ // BLYNK_WRITE(V1) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV1 = param.asInt(); // assigning incoming value from pin V1 to a variable mp3_set_volume(pinValueV1); terminal.print("Volume: "); terminal.println(pinValueV1); terminal.println(""); terminal.flush(); RdyFlagStateChange(); } } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V2) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV2 = param.asInt(); // assigning incoming value from pin V2 to a variable terminal.print("Access Ramp: "); terminal.flush(); RampLEDdown.setColor(LED_Red); // Set Ramp LEDs to red for travelling and unlocked RampLEDup.setColor(LED_Red); RampLEDdown.on(); RampLEDup.on(); // DC_loop(); if (pinValueV2 == 0) { audioflag = true; my_mp3_stop(); my_mp3_play(MP3_Folder, 34); rampTimer = timer.setTimeout(8000, rampDown); } else { audioflag = true; my_mp3_stop(); my_mp3_play(MP3_Folder, 33); rampTimer = timer.setTimeout(8000, rampUp); } terminal.flush(); } } //-------------------------------------------------------------------------------------------------- void rampDown() { rampdownflag = true; } //--------------------------------------------------------------------------------------------------
void rampUp() { rampupflag = true; } //--------------------------------------------------------------------------------------------------
BLYNK_WRITE(V6) // Cockpit Power On/Off { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV6 = param.asInt(); // assigning incoming value from pin V6 to a variable myDelay(10);
if (pinValueV6 == 0) { terminal.println("All Power Systems: OFF"); terminal.println(""); terminal.flush(); SW_LED[0] = false; // LED1 OFF SW_LED[1] = false; // LED2 OFF SW_LED[2] = false; // LED3 OFF SW_LED[3] = false; // LED4 OFF FullStripColor(0, 0, 0); EngineRunFlag = false; HyperdriveFlag = false; my_mp3_stop(); // MP3 stop MusicST = 0; } else { SW_LED[0] = true; // LED1 ON SW_LED[1] = true; // LED2 ON SW_LED[2] = true; // LED3 ON SW_LED[3] = true; // LED4 ON terminal.println("Cockpit Power: ON"); terminal.println(""); terminal.flush(); } RdyFlagStateChange(); } } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V7) // Engine Start/Stop { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV7 = param.asInt(); // assigning incoming value from pin V7 to a variable if (pinValueV6 == 0) { terminal.println("Engage main cockpit power."); terminal.println(""); terminal.flush(); EngineRunFlag = false; myDelay(100); pinValueV7 = 0; Blynk.virtualWrite(V7 , 0); myDelay(100); } else { if (pinValueV7 == 1) { my_mp3_stop(); terminal.println("Engine start sequence initiated..."); terminal.println(""); terminal.flush(); if (random(100) > 70) { my_mp3_play(1, 4); stall(26, 1); myDelay(1000); pinValueV7 = 0; Blynk.virtualWrite(V7 , 0); FullStripColor(0, 0, 0); terminal.println("Engine start failure."); terminal.println(""); terminal.flush(); EngineRunFlag = false;
myDelay(100); FullStripColor(0, 0, 0); if (random(10) > 4) { terminal.println("Stall Voice Comment"); terminal.println(""); terminal.flush(); EngineRunFlag = false; my_mp3_play(1, 32); } } else { my_mp3_play(1, 3); myDelay(3000); stall(10, 1); FullStripColor(0, 0, 255); terminal.println("Engines: ON"); terminal.println(""); terminal.flush(); EngineRunFlag = true; } } else { my_mp3_stop(); FullStripColor(0, 0, 0); terminal.println("Engines: Shut Down"); terminal.println(); terminal.flush(); EngineRunFlag = false;
} } RdyFlagStateChange(); } } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V8) // Hyperdrive On/Off { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV8 = param.asInt(); // assigning incoming value from pin V8 to a variable if (pinValueV7 == 0) { terminal.println("Hyperdrive failure: Engage primary engine drive."); terminal.println(""); terminal.flush(); pinValueV8 = 0; Blynk.virtualWrite(V8 , 0); RdyFlagStateChange(); } else { if (pinValueV8 == 0) { terminal.println("Hyperdrive jump complete."); terminal.println(""); terminal.flush(); FullStripColor(0, 0, 255); RdyFlagStateChange(); } else { EngineRunFlag = false; my_mp3_stop(); terminal.println("Hyperdrive co-ords plotted, jumping in 3...2...1.."); terminal.println(""); terminal.flush(); my_mp3_play(MP3_Folder, 6); for ( int i = 0; i < 35; i++ ) { FullStripColor(0, 0, 255); myDelay(20 + i * 2); FullStripColor(255, 255, 255); myDelay(20 + i); } hyperdriveTimer = timer.setTimeout(6000, hyperdrive); } } } } //-------------------------------------------------------------------------------------------------- void hyperdrive() { HyperdriveFlag = true; } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V9) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV9 = param.asInt(); // assigning incoming value from pin V9 to a variable if (pinValueV6 == 0) { terminal.println("Engage main cockpit power."); terminal.println(""); terminal.flush(); } else { if (pinValueV9 == 1) { audioflag = true; my_mp3_stop(); terminal.println("Firing."); terminal.println(""); terminal.flush(); if (random(1, 3) == 1) { my_mp3_play(MP3_Folder, 13); digitalWrite(43, HIGH); digitalWrite(44, LOW); cannonTimer = timer.setTimer(70, cannon1, 6); } else { cannonTimer = timer.setTimer(70, cannon2, 3); } } } } } //-------------------------------------------------------------------------------------------------- void cannon1() { digitalWrite(43, LOW); digitalWrite(44, HIGH); myDelay(70); digitalWrite(43, HIGH); digitalWrite(44, LOW); myDelay(70); cannonCount++; if (cannonCount == 6) { digitalWrite(43, LOW); digitalWrite(44, LOW); GunVoice++; if (GunVoice > 8) { GunVoice = 1; } my_mp3_stop(); my_mp3_play(MP3_Folder, 13 + GunVoice); cannonTimer = timer.setTimeout(4000, cannonEnd); } } //-------------------------------------------------------------------------------------------------- void cannon2() { my_mp3_play(MP3_Folder, 35); digitalWrite(43, HIGH); digitalWrite(44, LOW); cannonTimer = timer.setTimeout(100, cannon2a); } void cannon2a() { digitalWrite(43, LOW); cannonTimer = timer.setTimeout(600, cannon2b); } void cannon2b() { my_mp3_play(MP3_Folder, 35); digitalWrite(43, LOW); digitalWrite(44, HIGH); cannonTimer = timer.setTimeout(100, cannon2c); } void cannon2c() { digitalWrite(44, LOW); cannonTimer = timer.setTimeout(600, cannon2d); } void cannon2d() { cannonCount++; if (cannonCount == 3) { GunVoice++; if (GunVoice > 8) { GunVoice = 1; } // my_mp3_playend (); my_mp3_play(MP3_Folder, 13 + GunVoice); cannonTimer = timer.setTimeout(3000, cannonEnd); } } //-------------------------------------------------------------------------------------------------- void cannonEnd() { cannonFlag = true; } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V10) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV10 = param.asInt(); // assigning incoming value from pin V10 to a variable if (pinValueV6 == 0) { terminal.println("Engage main cockpit power."); terminal.println(""); pinValueV10 = 0; Blynk.virtualWrite(V10 , 0); } else { if (pinValueV10 == 0) { terminal.println("Headlights: OFF"); terminal.println(""); } else { terminal.println("Headlights: ON"); terminal.println(""); } } terminal.flush(); RdyFlagStateChange(); } } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V11) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV11 = param.asInt(); // assigning incoming value from pin V11 to a variable if (pinValueV6 == 0) { terminal.println("Engage main cockpit power."); terminal.println(""); pinValueV11 = 0; Blynk.virtualWrite(V11 , 0); } else { if (pinValueV11 == 0) { digitalWrite(36, LOW); // Holoboard Off digitalWrite(37, LOW); // Inspection pit Off digitalWrite(38, LOW); // Bed lights Off digitalWrite(39, LOW); // Passage 1 Floor Lights Off digitalWrite(40, LOW); // Passage 1 Wall Lights Off digitalWrite(41, LOW); // Passage 2 Floor Lights Off digitalWrite(42, LOW); // Passage 2 Wall Lights Off terminal.println("Hold Power: OFF"); terminal.println(""); } else { digitalWrite(36, HIGH); // Holoboard On digitalWrite(37, HIGH); // Inspection pit On digitalWrite(38, HIGH); // Bed lights On digitalWrite(39, HIGH); // Passage 1 Floor Lights On digitalWrite(40, HIGH); // Passage 1 Wall Lights On digitalWrite(41, HIGH); // Passage 2 Floor Lights On digitalWrite(42, HIGH); // Passage 2 Wall Lights On terminal.println("Hold Power: ON"); terminal.println(""); } } terminal.flush(); RdyFlagStateChange(); } } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V12) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV12 = param.asInt(); // assigning incoming value from pin V12 to a variable if (pinValueV6 == 0) { terminal.println("Engage main cockpit power."); terminal.println(""); pinValueV12 = 0; Blynk.virtualWrite(V12 , 0); } else { if (pinValueV12 == 0) { terminal.println("Landing Lights: OFF"); terminal.println(""); digitalWrite(48, LOW); } else { terminal.println("Landing Lights: ON"); terminal.println(""); digitalWrite(48, HIGH); } } terminal.flush(); RdyFlagStateChange(); } } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V13) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV13 = param.asInt(); // assigning incoming value from pin V13 to a variable if (pinValueV6 == 0) { terminal.println("Engage main cockpit power."); terminal.println(""); pinValueV13 = 0; Blynk.virtualWrite(V13 , 0); } else { if (pinValueV13 == 0) { terminal.println("Anti-Coll Lights: OFF"); terminal.println(""); digitalWrite(49, LOW);
} else { terminal.println("Anti-Coll Lights: ON"); terminal.println(""); digitalWrite(49, HIGH); } } terminal.flush(); RdyFlagStateChange(); } } //-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V14) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV14 = param.asInt(); // assigning incoming value from pin V2 to a variable if (pinValueV14 == 1) { audioflag = true; my_mp3_stop(); randomChatter = random(22, 33); my_mp3_play(MP3_Folder, randomChatter); // MUSIC ON chatterTimer = timer.setTimeout(6000, chatterEnd); } } } //-------------------------------------------------------------------------------------------------- void chatterEnd() { chatterFlag = true; }
//-------------------------------------------------------------------------------------------------- BLYNK_WRITE(V16) { if (RdyFlag == true) { RdyFlagStateChange(); pinValueV16 = param.asInt(); // assigning incoming value from pin V2 to a variable if (pinValueV16 == 0) { terminal.println("Music: OFF"); terminal.println(""); terminal.flush(); audioflag = false; } else { audioflag = true; my_mp3_stop(); terminal.println("Now Playing:"); terminal.println(MusicName[pinValueV16]); terminal.println(""); terminal.flush(); }
my_mp3_play(MP3_Folder, MusicID[pinValueV16]); // MUSIC ON
RdyFlagStateChange(); } }
//-------------------------------------------------------------------------------------------------- void myDelay(int milli) {
int end_time;
for (end_time = 1; end_time != milli; end_time++) { delay(1); if (end_time % 100 == 0) { // Blynk.run(); yield(); } } }
// ------------------------------------------------------------------------------------------------------------ // // ----------------------------- Functions to be processed at timer interrupt --------------------------------- // // ------------------------------------------------------------------------------------------------------------ //
void flash() { static long OLD_Vale = 3; long LED_Vale = 0;
for ( int i = 0; i < RandomLEDs; i++ ) { if (SW_VAL1[i] > 0) { // LED flashing processing SW_CNT[i]--; if (SW_On[i] == 1) // LED is on { if (SW_CNT[i] <= 0) { SW_On[i] = 0; SW_CNT[i] = SW_VAL2[i] + random(SW_RAN2[i]);
} } else { // LED is off if (SW_CNT[i] <= 0) { SW_On[i] = 1; SW_CNT[i] = SW_VAL1[i] + random(SW_RAN1[i]); } } } else { SW_On[i] = 1; // LED steady light } if (SW_LED[i] == true && SW_On[i] == 1) { digitalWrite(StartPIN + i, HIGH); //LED lit } else { digitalWrite(StartPIN + i, LOW); } //LED off } } //------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------
void stall(int L, boolean P) // Cockpit LED flashing processing to match power stall {
for ( int i = 0; i < L; i++ ) { FullStripColor(0, 0, 255); myDelay(70 + i); if (P == 1) { FullStripColor(0, 0, 0); } myDelay(70 + (i * 2)); FullStripColor(0, 0, 0); } FullStripColor(0, 0, 0);
}
//------------------------------------------------------------------------------------------------------------- void CheckEngines() { if (EngineRunFlag == true) { if (digitalRead(Busy_PIN) == HIGH) { if (audioflag == false) { my_mp3_play(MP3_Folder, 5); // Engine sound if engines on } } PixelRan1 = random(NUMPIXELS); PixelRan2 = random(NUMPIXELS); PixelRan3 = random(NUMPIXELS); PixelRan4 = random(NUMPIXELS); PixelRan5 = random(NUMPIXELS);
setPixel(PrevPixelRan1, 0, 0, 255); setPixel(PrevPixelRan2, 0, 0, 255); setPixel(PrevPixelRan3, 0, 0, 255); setPixel(PrevPixelRan4, 0, 0, 255); setPixel(PrevPixelRan5, 0, 0, 255);
setPixel(PixelRan1, 0, 0, 0); setPixel(PixelRan2, 0, 0, 0); setPixel(PixelRan3, 0, 0, 0); setPixel(PixelRan4, 0, 0, 0); setPixel(PixelRan5, 0, 0, 0);
PrevPixelRan1 = PixelRan1; PrevPixelRan2 = PixelRan2; PrevPixelRan3 = PixelRan3; PrevPixelRan4 = PixelRan4; PrevPixelRan5 = PixelRan5; FastLED.show();
}
}
//-------------------------------------------------------------------------------------------------------------
void setPixel(int Pixel, byte red, byte green, byte blue) {
LED_Array[Pixel].r = red; LED_Array[Pixel].g = green; LED_Array[Pixel].b = blue;
} //-------------------------------------------------------------------------------------------------------------
void FullStripColor(byte red, byte green, byte blue) { for (int pixelcount = 0; pixelcount < (NUMPIXELS); pixelcount++) { setPixel(pixelcount, red, green, blue); }
FastLED.show(); }
// ------------------------------------------------------------------------------------------------------------ // // -------------------------------------------- MP3 Sub-routines ---------------------------------------------- // // ------------------------------------------------------------------------------------------------------------ //
void my_mp3_playend() //MP3 Waiting for playback to finish { boolean play_state = digitalRead(Busy_PIN); do { play_state = digitalRead(Busy_PIN); } while (play_state == LOW); }
//-------------------------------------------------------------------------------------------------------------
void my_mp3_play(int F, int N) //MP3 playback {
mp3_play(N); }
//-------------------------------------------------------------------------------------------------------------
void my_mp3_stop() //MP3 stop {
mp3_stop(); } //------------------------------------------------------------------------------------------------------------- void RdyFlagStateChange() { if (RdyFlag == true) { RdyFlag = false;
Rdy1LED.off(); Rdy2LED.off(); Rdy3LED.off(); Rdy4LED.off(); } else { if (RdyFlag == false) { RdyFlag = true;
Rdy1LED.on(); Rdy2LED.on(); Rdy3LED.on(); Rdy4LED.on(); } } } //------------------------------------------------------------------------------------------------------------- void initialisation() { if (DC_RO == 0) { RampLEDup.setColor(LED_Green); RampLEDdown.off(); RampLEDup.on(); } else { RampLEDdown.setColor(LED_Green); RampLEDup.off(); RampLEDdown.on(); } Blynk.virtualWrite(V6 , 0); Blynk.virtualWrite(V7 , 0); Blynk.virtualWrite(V8 , 0); Blynk.virtualWrite(V9 , 0); Blynk.virtualWrite(V10 , 0); Blynk.virtualWrite(V11 , 0); Blynk.virtualWrite(V12 , 0); Blynk.virtualWrite(V13 , 0); Blynk.virtualWrite(V14 , 0); Blynk.virtualWrite(V16 , 0);
Rdy1LED.on(); Rdy2LED.on(); Rdy3LED.on(); Rdy4LED.on();
initialisationpass = false;
} //------------------------------------------------------------------------------------------------------------- void DC_loop() { DC_state1 = digitalRead(7); DC_state2 = digitalRead(8); if (DC_state1 == buttonON) { DC_RO = 1; } if (DC_state2 == buttonON) { DC_RO = 0; } Serial.print("DC_RO="); Serial.println(DC_RO); switch (DC_RO) { case 0: SW_LED[29] = true; analogWrite(DC_1A, 0); // Motor 1 forward rotation to A-1A pin analogWrite(DC_1B, 255); // Motor 1 to A-1 B pin // delay(500); DC_Stop1(); analogWrite(DC_1A, 0);// Motor 1 pause analogWrite(DC_1B, 0); SW_LED[29] = false; DC_RO = 1; break;
case 1: SW_LED[29] = true; analogWrite(DC_1A, 255);// Motor 1 Reverse rotation to A-1A pin analogWrite(DC_1B, 0); // Motor 1 to A-1 B pin // delay(500); DC_Stop2(); analogWrite(DC_1A, 0);// Motor 1 pause analogWrite(DC_1B, 0); DC_RO = 0; break;
case 2: analogWrite(DC_1A, 0); // Motor 1 forward rotation to A-1A pin analogWrite(DC_1B, 255); // Motor 1 to A-1 B pin // delay(500); DC_Stop3(); analogWrite(DC_1A, 0);// Motor 1 pause analogWrite(DC_1B, 0); break; } } //------------------------------------------------------------------------------------------------------------- void DC_Stop1() { Serial.println("DC_Stop1"); boolean DC_state1 = digitalRead(SW_1A); boolean DC_state2 = digitalRead(SW_1B);
do { DC_state1 = digitalRead(SW_1A); DC_state2 = digitalRead(SW_1B); } while (DC_state1 == buttonOFF); Serial.print("DC_state A1="); Serial.println(DC_state1); Serial.print("DC_state A2="); Serial.println(DC_state2); } //------------------------------------------------------------------------------------------------------------- void DC_Stop2() { Serial.println("DC_Stop2"); boolean DC_state1 = digitalRead(SW_1A); boolean DC_state2 = digitalRead(SW_1B);
do { DC_state1 = digitalRead(SW_1A); DC_state2 = digitalRead(SW_1B); } while (DC_state2 == buttonOFF); Serial.print("DC_state A1="); Serial.println(DC_state1); Serial.print("DC_state A2="); Serial.println(DC_state2); } //------------------------------------------------------------------------------------------------------------- void DC_Stop3() { Serial.println("DC_Stop3"); boolean DC_state1 = digitalRead(SW_1A); boolean DC_state2 = digitalRead(SW_1B);
do { DC_state1 = digitalRead(SW_1A); DC_state2 = digitalRead(SW_1B); } while (DC_state1 == buttonOFF and DC_state2 == buttonOFF); if (DC_state1 == buttonON) { DC_RO = 1; } if (DC_state2 == buttonON) { DC_RO = 0; } Serial.print("DC_state A1="); Serial.println(DC_state1); Serial.print("DC_state A2="); Serial.println(DC_state2); }
//---------------------------------------------------------------------------------------------------------------- //<><><><><><><><><><><><><><><><><><><><><><> INITIAL SET UP <><><><><><><><><><><><><><><><><><><><><><><><><><> //----------------------------------------------------------------------------------------------------------------
void setup() // Initial setup {
//--- DC motor --------------------------------------------------- pinMode(DC_1A, OUTPUT); pinMode(DC_1B, OUTPUT); analogWrite(DC_1A, 0);// Motor 1 pause analogWrite(DC_1B, 0); pinMode(SW_1A, INPUT_PULLUP); DC_RO = 2;
//-----------------------------------------------------------------
FastLED.addLeds<WS2811, NeopixelPin, GRB>(LED_Array, NUMPIXELS).setCorrection( TypicalLEDStrip ); FastLED.show();
for ( int i = 0; i < 51; i++ ) // LED Pins set as Output { pinMode(StartPIN + i, OUTPUT); }
Serial.begin(9600); Serial1.begin(9600); ESP8266_Serial.begin(ESP8266_BAUD); Blynk.begin(auth, wifi, ssid, pass);
//MP3 Initial setting Serial.println("INITIALISE MP3 PLAYER"); mp3_set_serial (Serial1); //set softwareSerial for DFPlayer-mini mp3 module mp3_stop(); //MP3 stop delay(1000); //MP3 Waiting for initial activation mp3_set_volume(MP3_Vol); //MP3 Volume initial set delay(200); //MP3 wait mp3_stop(); //MP3 stop delay(200); //MP3 wait
DC_state1 = digitalRead(7); DC_state2 = digitalRead(8); if (DC_state1 == buttonON) { DC_RO = 1; } if (DC_state2 == buttonON) { DC_RO = 0; } Serial.print("DC_state1 ="); Serial.println(DC_state1); Serial.print("DC_state2 ="); Serial.println(DC_state2); Serial.print("DC_RO="); Serial.println(DC_RO); Serial.println("START ININ END"); //my_mp3_play(MP3_Folder, 1);
timer.setInterval(10, flash); // Timer1.initialize(10000); //Timer interrupt initialization //Timer1.attachInterrupt(flash, 10000); //Timer interrupt setting
// timer.setInterval(80, flash); terminal.println("F a l c o n"); terminal.println("C o n t r o l l e r"); terminal.println("v3.0 by Chip"); terminal.println(""); terminal.flush(); Serial.println("Initialisation Complete"); myDelay(100);
}
//---------------------------------------------------------------------------------------------------------------- //<><><><><><><><><><><><><><><><><><><><><><><><><><> MAIN LOOP <><><><><><><><><><><><><><><><><><><><><><><><><> //----------------------------------------------------------------------------------------------------------------
void loop() { Blynk.run(); myDelay(10); timer.run(); if (initialisationpass == true) { initialisation(); } CheckEngines(); if (rampdownflag == true) { terminal.println("Down and Locked"); terminal.println(""); terminal.flush(); RampLEDdown.setColor(LED_Green); RampLEDdown.on(); RampLEDup.off(); rampdownflag = false; audioflag = false; RdyFlagStateChange(); }
if (rampupflag == true) { terminal.println("Up and Locked"); terminal.println(""); terminal.flush(); RampLEDup.setColor(LED_Green); RampLEDdown.off(); RampLEDup.on(); rampupflag = false; audioflag = false; RdyFlagStateChange(); } if (HyperdriveFlag == true) { terminal.println("Hyperdrive jump complete."); terminal.println(""); terminal.flush(); pinValueV8 = 0; Blynk.virtualWrite(V8, 0); EngineRunFlag = true; FullStripColor(0, 0, 255); HyperdriveFlag = false; RdyFlagStateChange(); } if (cannonFlag == true) { terminal.println("Good shooting kid.. Cannons to standby"); terminal.println(""); terminal.flush(); pinValueV9 = 0; Blynk.virtualWrite(V9 , 0); cannonCount = 0; cannonFlag = false; audioflag = false; RdyFlagStateChange(); } if (chatterFlag == true) { pinValueV14 = 0; Blynk.virtualWrite(V14 , 0); chatterFlag = false; audioflag = false; RdyFlagStateChange(); } }
//-------------------------------------------------------------------------------------------------------------
I will get around to posting the circuit diagram at somepoint if anyone is interested.
|