Professional Documents
Culture Documents
***********************************************//
// BANTAM.EARTH //
// https://bantam.earth/ //
//*****************************************************************************
***********************************************//
//---------------------------------------------------
// 1. Libreries
//---------------------------------------------------
#include "Arduino.h"
#include <DFRobotDFPlayerMini.h>
#include <Wire.h>
#include <dht.h>
#include <math.h>
#include <LiquidCrystal_I2C.h>
//----------------------------------------------------
// 2. Pins
//----------------------------------------------------
dht DHT;
DFRobotDFPlayerMini myDFPlayer;
#define xPin A1
#define yPin A2
#define kPin 12
#define DHT11_PIN 11 //assign DHT11 to pin
#define StormLED 10
#define StarsLED 9
#define Fish1LED 8
#define Fish2LED 7
#define SkyL1LED 6
#define SkyL2LED 5
#define SkyL3LED 3
#define SkyL4LED 2
#define RelayPin1 52
#define RelayPin2 50
#define RelayPin3 48
#define RelayPin4 46
#define RelayPin5 44
#define RelayPin6 42
#define RelayPin7 40
#define RelayPin8 38
//----------------------------------------------------
//----------------------------------------------------
int bsy = 0;
int sensorValue = 0;
boolean isPlaying = false;
//Bluetooth
byte dataFromBT;
byte State;
int FanState = 0;
int FogState = 0;
int RainState = 0;
int SunState = 0;
int BaskState = 0;
int SkyState = 0;
//String string;
//char command;
//int RESET = 7;
int StormLEDPos = 0;
int StarsLEDPos = 0;
int FishLED1Pos = 0;
int FishLED2Pos = 0;
int SkyL1LEDPos = 0;
int SkyL2LEDPos = 0;
int SkyL3LEDPos = 0;
int SkyL4LEDPos = 0;
int StormLEDSet = 0;
int StarsLEDSet = 0;
int FishLED1Set = 0;
int FishLED2Set = 0;
int SkyL1LEDSet = 0;
int SkyL2LEDSet = 0;
int SkyL3LEDSet = 0;
int SkyL4LEDSet = 0;
//Storm Values
int CloudBrightness = 0;
int StormSpeed = 1;
int ThermistorPin = 0;
int Vo;
float R1 = 10000;
int tCount1;
bool refresh;//lcd clear On/Of
//ReadJoystick
int joyRead;
int joyPos;
int lastJoyPos;
int joyButtonPushed;
long lastDebounceTime = 0;
int pushedTime = 0;
//-------Dead Pins-----//
//--------Relay states-----------//
byte back[8] = {
0b00100,
0b01000,
0b11111,
0b01001,
0b00101,
0b00001,
0b00001,
0b11111
};
byte arrow[8] = {
0b01000,
0b00100,
0b00010,
0b11111,
0b00010,
0b00100,
0b01000,
0b00000
};
//=============================================================================
==============================================
// SETUP
//=============================================================================
==============================================
void setup() {
//----------------------------------------------------
// S1. Pins
//----------------------------------------------------
pinMode(buusyPin, INPUT);
pinMode(StormLED,OUTPUT);
pinMode(StarsLED,OUTPUT);
pinMode(Fish1LED,OUTPUT);
pinMode(Fish2LED,OUTPUT);
pinMode(SkyL1LED,OUTPUT);
pinMode(SkyL2LED,OUTPUT);
pinMode(SkyL3LED,OUTPUT);
pinMode(SkyL4LED,OUTPUT);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(kPin, INPUT_PULLUP);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
pinMode(RelayPin5, OUTPUT);
pinMode(RelayPin6, OUTPUT);
pinMode(RelayPin7, OUTPUT);
pinMode(RelayPin8, OUTPUT);
//----------------------------------------------------
// S2. Objects
//----------------------------------------------------
resetallrelays();
Serial2.begin(9600);
Serial1.begin(9600);
//Serial.println();
//Serial.println(F("Unable to begin:"));
else{
//myDFPlayer.reset();
myDFPlayer.volumeUp(); //Volume Up
myDFPlayer.play(4);
lcd.begin(20,4);
lcd.createChar(1, back);
lcd.createChar(2, arrow);
lcd.setCursor(4,1);
lcd.print("Bantam.Earth");
lcd.setCursor(8,3);
lcd.print("v1.10");
delay(3000);
lcd.clear();
readTime = 0;
myDFPlayer.play(1);
}
//=============================================================================
==============================================
// LOOP
//=============================================================================
==============================================
void loop() {
if (myDFPlayer.available()) {
updatestatistics();
readJoystick();
navigationFunctioner();
myMenu();
relayStates();
bluetooth();
clearSkyMode();
// myDFPlayer.stop();
// isPlaying = false;
// }println
}
else{
cloudySkyMode();
if(page_counter !=1){
autoGoBackToHomePage();
//=============================================================================
==============================================
//=============================================================================
==============================================
void updatestatistics(){
readTime = millis();
AirTemp = DHT.temperature;
AirTemp *= 1.8;
AirTemp += 30;
Vo = analogRead(ThermistorPin);
logR2 = log(R2);
Serial1.print("Stats:");
Serial1.print((int)Air);
//Serial1.print(" F");
Serial1.print("|");
Serial1.print((int)Humidity);
//Serial1.print(" %");
Serial1.print("|");
Serial1.print((int)Water);
//Serial1.print(" F");
Serial1.print("|");
if(subpage2_counter == 0){
Serial1.print("Sky Disabled");
Serial1.print("Morning");
Serial1.print("Noon");
}
else if(subpage2_counter == 3){
Serial1.print("Evening");
Serial1.print("Night");
Serial1.print("Storm");
Serial1.print("StatsEnd");
Serial1.print("Setts:");
Serial1.print((int)FanMode);
Serial1.print("|");
Serial1.print((int)FogMode);
Serial1.print("|");
Serial1.print((int)RainMode);
Serial1.print("|");
Serial1.print((int)SunMode);
Serial1.print("|");
Serial1.print((int)BaskMode);
Serial1.print("|");
Serial1.print((int)SkyMode);
Serial1.print("SettsEnd");
//=============================================================================
==============================================
//=============================================================================
==============================================
void writestatistics(){
lcd.setCursor(1,1);
lcd.print("Temp: A:");
lcd.print(AirTemp, 0);
lcd.print((char)223);
lcd.print(" W:");
lcd.print(WaterTemp, 0);
lcd.print((char)223);
//lcd.print("F");
lcd.print("Humidity ");
lcd.print(DHT.humidity, 0);
lcd.print("%");
//=============================================================================
==============================================
// MENUS
//=============================================================================
==============================================
//----------------------------------------------------------------------------------------------------------------------
// MAIN MENU(PageCounter1)
//----------------------------------------------------------------------------------------------------------------------
void myMenu(){
switch (page_counter) {
case 1:{
homeScreen();
break;
case 2: {
fanControl();
break;
case 3: {
fogControl();
break;
case 4: {
rainControl();
break;
case 5: {
sunControl();
break;
case 6: {
BaskingControl();
break;
case 7: {
skyControl();
break;
//----------------------------------------------------------------------------------------------------------------------
// SUB MENU(PageCounter2)
//----------------------------------------------------------------------------------------------------------------------
void SkyMenu(){
switch (subpage2_counter) {
case 1:{
morning();
break;
case 2: {
noon();
break;
case 3: {
evening();
break;
case 4: {
night();
break;
case 5: {
storm();
break;
case 0: {
TurnOfSky();
}
break;
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void morning(){
lcd.setCursor(5,2);
lcd.print(" Morning");
StormLEDSet = 0;
StarsLEDSet = 0;
FishLED1Set = 15;
FishLED2Set = 0;
SkyL1LEDSet = 65;
SkyL2LEDSet = 65;
SkyL3LEDSet = 65;
SkyL4LEDSet = 65;
void noon(){
lcd.setCursor(5,2);
StormLEDSet = 0;
StarsLEDSet = 0;
FishLED1Set = 65;
FishLED2Set = 0;
SkyL1LEDSet = 200;
SkyL2LEDSet = 200;
SkyL3LEDSet = 200;
SkyL4LEDSet = 200;
void evening(){
lcd.setCursor(5,2);
lcd.print(" Evening");
StormLEDSet = 0;
StarsLEDSet = 0;
FishLED1Set = 25;
FishLED2Set = 1;
SkyL1LEDSet = 25;
SkyL2LEDSet = 25;
SkyL3LEDSet = 25;
SkyL4LEDSet = 25;
void night(){
lcd.setCursor(5,2);
StormLEDSet = 2;
StarsLEDSet = 1;
FishLED1Set = 0;
FishLED2Set = 5;
SkyL1LEDSet = 0;
SkyL2LEDSet = 0;
SkyL3LEDSet = 0;
SkyL4LEDSet = 0;
void storm(){
lcd.setCursor(5,2);
StormLEDSet = 0;
StarsLEDSet = 0;
FishLED1Set = 5;
FishLED2Set = 5;
SkyL1LEDSet = 255;
SkyL2LEDSet = 255;
SkyL3LEDSet = 255;
SkyL4LEDSet = 255;
void TurnOfSky(){
lcd.setCursor(5,2);
lcd.print(" ");
StormLEDSet = 0;
StarsLEDSet = 0;
FishLED1Set = 0;
SkyL1LEDSet = 0;
SkyL2LEDSet = 0;
SkyL3LEDSet = 0;
SkyL4LEDSet = 0;
//----------------------------------------------------------------------------------------------------------------------
// HOME
//----------------------------------------------------------------------------------------------------------------------
void homeScreen(){
if (refresh){lcd.clear();refresh=0;}
writestatistics();
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void fanControl(){
//Static objects
lcd.setCursor(4,0);
lcd.print("Fan Control:");
//----------------------------------------
// page controls
//----------------------------------------
lcd.setCursor(15,3);
lcd.write(byte(1)); //Return custom char
else{ //If subpage higher than 2 (total of items) return to first item
subpage_counter=1;
lcd.setCursor(15,3);
lcd.setCursor(15,3);
subpage_counter=0;
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(15,3);
lcd.print(" ");
}
last_sel=current_sel; //Save last state of select button
//----------------------------------------
// item control 1
//----------------------------------------
if(subpage_counter==1){
lcd.setCursor(14,3);
lcd.setCursor(7,1);
lcd.write(byte(2));
relay8_state=LOW;
last_sel=current_sel;
relay8_state=HIGH;
last_sel=current_sel;
if(relay8_state==HIGH){
lcd.setCursor(8,1);
lcd.print("OFF");
if(FanState !=0){
FanState = 0;
else if(relay8_state==LOW){
lcd.setCursor(8,1);
lcd.print("ON ");
if(FanState !=1){
FanState = 1;
//----------------------------------------
// BACK controls
//----------------------------------------
if(subpage_counter==2){
lcd.setCursor(7,1);
lcd.write(byte(2));
//----------------------------------------------------------------------------------------------------------------------
// MENU OPTION TWO
//----------------------------------------------------------------------------------------------------------------------
void fogControl(){
//Static objects
lcd.setCursor(4,0);
lcd.print("Fog Control:");
//----------------------------------------
// page controls
//----------------------------------------
lcd.setCursor(15,3);
else{ //If subpage higher than 2 (total of items) return to first item
subpage_counter=1;
lcd.setCursor(15,3);
lcd.setCursor(15,3);
subpage_counter=0;
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(15,3);
lcd.print(" ");
//----------------------------------------
// item control 1
//----------------------------------------
if(subpage_counter==1){
lcd.setCursor(14,3);
lcd.setCursor(7,1);
lcd.write(byte(2));
relay2_state=LOW;
last_sel=current_sel;
relay2_state=HIGH;
last_sel=current_sel;
if(relay2_state==HIGH){
lcd.setCursor(8,1);
lcd.print("OFF");
if(FogState !=0){
FogState = 0;
else if(relay2_state==LOW){
lcd.setCursor(8,1);
lcd.print("ON ");
if(FogState !=1){
FogState = 1;
//----------------------------------------
// BACK controls
//----------------------------------------
if(subpage_counter==2){
lcd.setCursor(7,1);
lcd.write(byte(2));
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void rainControl(){
//Static objects
lcd.setCursor(4,0);
lcd.print("Rain Control:");
//----------------------------------------
// page controls
//----------------------------------------
lcd.setCursor(15,3);
else{ //If subpage higher than 2 (total of items) return to first item
subpage_counter=1;
lcd.setCursor(15,3);
lcd.setCursor(15,3);
subpage_counter=0;
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(15,3);
lcd.print(" ");
//----------------------------------------
// item control 1
//----------------------------------------
if(subpage_counter==1){
lcd.setCursor(14,3);
lcd.setCursor(7,1);
lcd.write(byte(2));
relay3_state=LOW;
last_sel=current_sel;
relay3_state=HIGH;
joyButtonPushed = 0; pushedTime = 0; myDFPlayer.play(6);
last_sel=current_sel;
if(relay3_state==HIGH){
lcd.setCursor(8,1);
lcd.print("OFF");
if(RainState !=0){
RainState = 0;
else if(relay3_state==LOW){
lcd.setCursor(8,1);
lcd.print("ON ");
if(RainState !=1){
RainState = 1;
//----------------------------------------
// BACK controls
//----------------------------------------
if(subpage_counter==2){
lcd.setCursor(7,1);
lcd.print(" "); //Delete last arrow position
lcd.write(byte(2));
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void sunControl(){
//Static objects
lcd.setCursor(4,0);
lcd.print("Sun Control:");
//----------------------------------------
// page controls
//----------------------------------------
lcd.setCursor(15,3);
else{ //If subpage higher than 2 (total of items) return to first item
subpage_counter=1;
lcd.setCursor(15,3);
lcd.setCursor(15,3);
subpage_counter=0;
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(15,3);
lcd.print(" ");
//----------------------------------------
// item control 1
//----------------------------------------
//First item control(subpage_counter =1) Sun Power
if(subpage_counter==1){
lcd.setCursor(14,3);
lcd.setCursor(7,1);
lcd.write(byte(2));
relay4_state=LOW;
last_sel=current_sel;
relay4_state=HIGH;
last_sel=current_sel;
if(relay4_state==HIGH){
lcd.setCursor(8,1);
lcd.print("OFF");
if(SunState !=0){
SunState = 0;
}
else if(relay4_state==LOW){
lcd.setCursor(8,1);
lcd.print("ON ");
if(SunState !=1){
SunState = 1;
//----------------------------------------
// BACK controls
//----------------------------------------
if(subpage_counter==2){
lcd.setCursor(7,1);
lcd.write(byte(2));
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void BaskingControl(){
//Static objects
lcd.setCursor(4,0);
lcd.print("Bask Control:");
//----------------------------------------
// page controls
//----------------------------------------
lcd.setCursor(15,3);
else{ //If subpage higher than 2 (total of items) return to first item
subpage_counter=1;
lcd.setCursor(15,3);
lcd.setCursor(15,3);
lcd.write(byte(1)); //Return custom char
subpage_counter=0;
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(15,3);
lcd.print(" ");
//----------------------------------------
// item control 1
//----------------------------------------
if(subpage_counter==1){
lcd.setCursor(14,3);
lcd.setCursor(7,1);
lcd.write(byte(2));
relay5_state=LOW;
joyButtonPushed = 0; pushedTime = 0; myDFPlayer.play(6);
last_sel=current_sel;
relay5_state=HIGH;
last_sel=current_sel;
if(relay5_state==HIGH){
lcd.setCursor(8,1);
lcd.print("OFF");
if(BaskState !=0){
BaskState = 0;
else if(relay5_state==LOW){
lcd.setCursor(8,1);
lcd.print("ON ");
if(BaskState !=1){
BaskState = 1;
//----------------------------------------
// BACK controls
//----------------------------------------
if(subpage_counter==2){
lcd.setCursor(7,1);
lcd.write(byte(2));
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void skyControl(){
//Static objects
lcd.setCursor(4,0);
lcd.print("Sky Control:");
//----------------------------------------
// page controls
//----------------------------------------
lcd.setCursor(15,3);
lcd.setCursor(15,3);
else{ //If subpage higher than 2 (total of items) return to first item
subpage_counter=1;
lcd.setCursor(15,3);
lcd.setCursor(15,3);
lcd.setCursor(15,3);
lcd.setCursor(15,3);
lcd.setCursor(15,3);
lcd.setCursor(15,3);
lcd.setCursor(15,3);
lcd.setCursor(15,3);
subpage_counter=0;
lcd.setCursor(14,3);
lcd.print(" ");
lcd.setCursor(15,3);
lcd.print(" ");
//----------------------------------------
// item control 1
//----------------------------------------
//First item control(subpage_counter =1) Sky Power
if(subpage_counter==1){
lcd.setCursor(14,3);
lcd.setCursor(4,2);
lcd.print(" ");
lcd.setCursor(7,1);
lcd.write(byte(2));
relay6_state=LOW;
subpage2_counter =1;
last_sel=current_sel;
relay6_state=HIGH;
subpage2_counter =0;
last_sel=current_sel;
if(relay6_state==HIGH){
lcd.setCursor(8,1);
lcd.print("OFF");
SkyMenu();
else if(relay6_state==LOW){
lcd.setCursor(8,1);
lcd.print("ON ");
SkyMenu();
//----------------------------------------
// item control 2
//----------------------------------------
lcd.setCursor(7,1);
lcd.setCursor(14,3);
lcd.setCursor(4,2);
lcd.write(byte(2));
if(subpage2_counter <5){
subpage2_counter ++;
}
subpage2_counter =1;
last_sel=current_sel;
if(subpage2_counter >1){
subpage2_counter --;
subpage2_counter =5;
last_sel=current_sel;
//----------------------------------------
// BACK controls
//----------------------------------------
if(subpage_counter==3){
lcd.setCursor(7,1);
lcd.setCursor(4,2);
lcd.print(" ");
lcd.write(byte(2));
//=============================================================================
==============================================
// NIGHT/DAY FUNCTIONALITY
//=============================================================================
==============================================
void clearSkyMode(){
//--------------------------------
// SOUND
//--------------------------------
//Sky Of
if(SkyState !=0){
SkyState = 0;
//Morning
//Serial.println(digitalRead(buusyPin));
if(digitalRead(buusyPin) !=0 && subpage2_counter ==1 && subpage_counter ==0){
if(SkyState !=1){
SkyState = 1;
myDFPlayer.volume (15);
myDFPlayer.play(10);
buusyPin ==0;
//Noon
// Serial.println(digitalRead(buusyPin));
if(SkyState !=2){
SkyState = 2;
myDFPlayer.volume (15);
myDFPlayer.play(11);
buusyPin ==0;
//Evening
//Serial.println(digitalRead(buusyPin));
if(SkyState !=3){
SkyState = 3;
myDFPlayer.volume (17);
myDFPlayer.play(12);
buusyPin ==0;
//Night
// Serial.println(digitalRead(buusyPin));
if(SkyState !=4){
SkyState = 4;
myDFPlayer.volume (18);
myDFPlayer.play(13);
buusyPin ==0;
//--------------------------------
// LIGHTS
//--------------------------------
if(StormLEDPos != StormLEDSet){
StormLEDPos++;
analogWrite(StormLED,StormLEDPos);
StormLEDPos--;
analogWrite(StormLED,StormLEDPos);
}
}
if(StarsLEDPos != StarsLEDSet){
StarsLEDPos++;
analogWrite(StarsLED,StarsLEDPos);
StarsLEDPos--;
analogWrite(StarsLED,StarsLEDPos);
if(FishLED1Pos != FishLED1Set){
FishLED1Pos++;
analogWrite(Fish1LED,FishLED1Pos);
FishLED1Pos--;
analogWrite(Fish1LED,FishLED1Pos);
if(FishLED2Pos != FishLED2Set){
FishLED2Pos++;
analogWrite(Fish2LED,FishLED2Pos);
}
FishLED2Pos--;
analogWrite(Fish2LED,FishLED2Pos);
if(SkyL1LEDPos != SkyL1LEDSet){
SkyL1LEDPos++;
analogWrite(SkyL1LED,SkyL1LEDPos);
SkyL1LEDPos--;
analogWrite(SkyL1LED,SkyL1LEDPos);
if(SkyL2LEDPos != SkyL2LEDSet){
SkyL2LEDPos++;
analogWrite(SkyL2LED,SkyL2LEDPos);
SkyL2LEDPos--;
analogWrite(SkyL2LED,SkyL2LEDPos);
}
}
if(SkyL3LEDPos != SkyL3LEDSet){
SkyL3LEDPos++;
analogWrite(SkyL3LED,SkyL3LEDPos);
SkyL3LEDPos--;
analogWrite(SkyL3LED,SkyL3LEDPos);
if(SkyL4LEDPos != SkyL4LEDSet){
SkyL4LEDPos++;
analogWrite(SkyL4LED,SkyL4LEDPos);
SkyL4LEDPos--;
analogWrite(SkyL4LED,SkyL4LEDPos);
//----------------------------------------------------------------------------------------------------------------------
// CLOUDS/LIGHTNING FUNCTIONALITY
//----------------------------------------------------------------------------------------------------------------------
void cloudySkyMode(){
if(SkyState !=5){
SkyState = 5;
if(StarsLEDPos != StarsLEDSet){
StarsLEDPos++;
analogWrite(StarsLED,StarsLEDPos);
StarsLEDPos--;
analogWrite(StarsLED,StarsLEDPos);
if(FishLED1Pos != FishLED1Set){
FishLED1Pos++;
analogWrite(Fish1LED,FishLED1Pos);
FishLED1Pos--;
analogWrite(Fish1LED,FishLED1Pos);
if(FishLED2Pos != FishLED2Set){
if(FishLED2Pos < FishLED2Set){
FishLED2Pos++;
analogWrite(Fish2LED,FishLED2Pos);
FishLED2Pos--;
analogWrite(Fish2LED,FishLED2Pos);
//--------------------------------
// LIGHTNING
//--------------------------------
if(StormLEDPos != StormLEDSet){
StormLEDPos++;
analogWrite(StormLED,StormLEDPos);
StormLEDPos--;
analogWrite(StormLED,StormLEDPos);
//--------------------------------
// CLOUDS
//--------------------------------
unsigned long currentCloudMillis = millis(); //call current millis
Serial.println(CloudreadTime);
CloudBrightness = CloudBrightnessMin;
CloudBrightness = CloudBrightnessMax;
CloudreadTime = 0;
//----------Cloud 1------------
SkyL1LEDPos += StormSpeed;
analogWrite(SkyL1LED,SkyL1LEDPos);
CloudBrightness = CloudBrightnessMax;
}
else if(SkyL1LEDPos > CloudBrightness){
SkyL1LEDPos -= StormSpeed;
analogWrite(SkyL1LED,SkyL1LEDPos);
CloudBrightness = CloudBrightnessMin;
//----------Cloud 2------------
if (SkyL2LEDPos != CloudBrightness){
analogWrite(SkyL2LED,SkyL2LEDPos);
analogWrite(SkyL2LED,SkyL2LEDPos);
//----------Cloud 3------------
if (SkyL3LEDPos != CloudBrightness){
analogWrite(SkyL3LED,SkyL3LEDPos);
SkyL3LEDPos -= StormSpeed+2;
analogWrite(SkyL3LED,SkyL3LEDPos);
//----------Cloud 4------------
if (SkyL4LEDPos != CloudBrightness){
analogWrite(SkyL4LED,SkyL4LEDPos);
analogWrite(SkyL4LED,SkyL4LEDPos);
//--------------------------------
// SOUND
//--------------------------------
//Serial.println(digitalRead(buusyPin));
myDFPlayer.volume (25);
myDFPlayer.play(14);
//isPlaying = true;
//Serial.println(digitalRead(buusyPin));
sensorValue = analogRead(sensorPin);
//Serial.println(sensorValue);
//Serial.println(" ");
StormLEDPos=255;
analogWrite(StormLED,StormLEDPos);
StormLEDPos=0;
analogWrite(StormLED,StormLEDPos);
bsy = digitalRead(buusyPin);
//=============================================================================
==============================================
//=============================================================================
==============================================
void autoGoBackToHomePage(){
lcd.clear();
subpage_counter=0;
page_counter=1; //Go back to home page
joyButtonPushed = 0; pushedTime = 0;
previousMillis = currentMillis;
//=============================================================================
==============================================
// NAVIGATION FUNCTIONALITY
//=============================================================================
==============================================
void navigationFunctioner(){
//Page Right
else{
page_counter= 2; //If higher than 3 (last page) stay on page 3(change to 1 if you
want to rotate)
current_sel = HIGH;
//Page Left
else{
page_counter= pages; //If lower than 1(first page) stay on page 1(change to 3 if
you want to rotate)
current_sel = HIGH;
}
last_sel = current_sel; //Save down button last state
if(page_counter !=1){
lcd.setCursor(0,0);
lcd.print(page_counter-1);
lcd.setCursor(1,0);
lcd.print(".");
if(page_counter >9){
lcd.setCursor(0,0);
lcd.print(page_counter-1);
lcd.setCursor(2,0);
lcd.print(".");
//=============================================================================
==============================================
// BUTTON DEBOUNCER
//=============================================================================
==============================================
delay(5);
current = digitalRead(pin);
return current;
//=============================================================================
==============================================
// JOYSTICK CONTROLLER
//=============================================================================
==============================================
int readJoystick(){
int x = analogRead(xPin);
int y = analogRead(yPin);
int k = digitalRead(kPin);
if(x>600){joyRead=1; //x+
}else if(!k){joyRead=5;
}else{joyRead=0;}
joyButtonPushed =joyPos;
if (joyRead != 0){
pushedTime++;
pushedTime = 0;
lastJoyPos=joyRead;
//=============================================================================
==============================================
// RELAY STATES
//=============================================================================
==============================================
void relayStates(){
digitalWrite(RelayPin1,HIGH);
digitalWrite(RelayPin1,LOW);
digitalWrite(RelayPin2,HIGH);
digitalWrite(RelayPin2,LOW);
digitalWrite(RelayPin3,HIGH);
digitalWrite(RelayPin3,LOW);
digitalWrite(RelayPin4,HIGH);
digitalWrite(RelayPin4,LOW);
digitalWrite(RelayPin5,LOW);
digitalWrite(RelayPin6,HIGH);
digitalWrite(RelayPin6,LOW);
digitalWrite(RelayPin7,HIGH);
digitalWrite(RelayPin7,LOW);
digitalWrite(RelayPin8,HIGH);
digitalWrite(RelayPin8,LOW);
//----------------------------------------------------------------------------------------------------------------------
// turn of all relays
//----------------------------------------------------------------------------------------------------------------------
void resetallrelays(){
digitalWrite(RelayPin1, HIGH);
digitalWrite(RelayPin2, HIGH);
digitalWrite(RelayPin3, HIGH);
digitalWrite(RelayPin4, HIGH);
digitalWrite(RelayPin5, HIGH);
digitalWrite(RelayPin6, HIGH);
digitalWrite(RelayPin7, HIGH);
digitalWrite(RelayPin8, HIGH);
//=============================================================================
==============================================
// BLUETOOTH
//=============================================================================
==============================================
void bluetooth(){
if(Serial1.available() > 0){ // Checks whether data is comming from the serial port
State = dataFromBT;
if (State == '1') {
// Turn of FAN
page_counter=2;
relay8_state=HIGH;
if(FanState !=0){
FanState = 0;
page_counter=1;
State = 0;
// Turn on FAN
page_counter=2;
relay8_state=LOW;
if(FanState !=1){
FanState = 1;
page_counter=1;
State = 0;
if (State == '3') {
// Turn of Fog
page_counter=3;
relay2_state=HIGH;
if(FogState !=0){
FogState = 0;
page_counter=1;
State = 0;
// Turn on Fog
page_counter=3;
relay2_state=LOW;
if(FogState !=1){
FogState = 1;
page_counter=1;
State = 0;
if (State == '5') {
// Turn of RAIN
page_counter=4;
relay3_state=HIGH;
if(RainState !=0){
RainState = 0;
page_counter=1;
State = 0;
// Turn on RAIN
page_counter=4;
relay3_state=LOW;
if(RainState !=1){
RainState = 1;
page_counter=1;
State = 0;
if (State == '7') {
// Turn of SUN
page_counter=5;
relay4_state=HIGH;
if(SunState !=0){
SunState = 0;
page_counter=1;
State = 0;
// Turn on SUN
page_counter=5;
relay4_state=LOW;
if(SunState !=1){
SunState = 1;
page_counter=1;
State = 0;
if (State == '9') {
// Turn of BASK
page_counter=6;
relay5_state=HIGH;
if(BaskState !=0){
BaskState = 0;
page_counter=1;
State = 0;
// Turn on BASK
page_counter=6;
relay5_state=LOW;
if(BaskState !=1){
BaskState = 1;
page_counter=1;
State = 0;
}
if (State == 'o') {
// Turn of SKY
myDFPlayer.stop();
page_counter=7;
relay6_state=HIGH;
subpage2_counter =0;
subpage_counter =0;
SkyMenu();
lcd.clear();
page_counter=1;
State = 0;
clearSkyMode();
myDFPlayer.stop();
page_counter=7;
relay6_state=LOW;
subpage2_counter =1;
subpage_counter =0;
SkyMenu();
lcd.clear();
page_counter=1;
State = 0;
clearSkyMode();
}else if ( State == 'd') {
myDFPlayer.stop();
page_counter=7;
relay6_state=LOW;
subpage2_counter =2;
subpage_counter =0;
SkyMenu();
lcd.clear();
page_counter=1;
State = 0;
clearSkyMode();
myDFPlayer.stop();
page_counter=7;
relay6_state=LOW;
subpage2_counter =3;
subpage_counter =0;
SkyMenu();
lcd.clear();
page_counter=1;
State = 0;
clearSkyMode();
myDFPlayer.stop();
page_counter=7;
relay6_state=LOW;
subpage2_counter =4;
subpage_counter =0;
SkyMenu();
lcd.clear();
page_counter=1;
State = 0;
clearSkyMode();
myDFPlayer.stop();
page_counter=7;
relay6_state=LOW;
subpage2_counter =5;
subpage_counter =0;
SkyMenu();
lcd.clear();
page_counter=1;
State = 0;
cloudySkyMode();
}
}
//=============================================================================
==============================================
// DEBUG DFPLAYER
//=============================================================================
==============================================
switch (type) {
case TimeOut:
// Serial.println(F("Time Out!"));
break;
case WrongStack:
// Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
// Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
// Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
// Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
// Serial.print(F("Number:"));
// Serial.print(value);
break;
case DFPlayerError:
// Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
break;
case Sleeping:
// Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
break;
case CheckSumNotMatch:
break;
case FileIndexOut:
break;
case FileMismatch:
break;
case Advertise:
// Serial.println(F("In Advertise"));
break;
default:
break;
break;
default:
break;