Hello Friends,i have been helping a friend to develop a code, i have in the loop
menuPrincipal()
since is a simulating device for my airsoft games, i wanted to put some fading lights, but i added to the code and only get the menuPrincipal() part only working. if i delete that and leave the rest then i get he fading lights. heres my code to see if you guys can help, and sry fr my poor knowledge, since my friend developed the code but this small thing its making us crazy.
#include <Wire.h>
#include <Keypad.h>
//#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
/*|
Arduino Bomb Pro
The circuit:
* More info at : http://yin.mainstreamds.com/
If you need some help mail me to yinbot@gmail.com
created 4,Sep, 2010
Modified 27 june 2013
by Ignacio Lillo
*/
//LiquidCrystal_I2C lcd(0x38,16,2);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{
'1','2','3','a' }
,
{
'4','5','6','b' }
,
{
'7','8','9','c' }
,
{
'*','0','#','d' }
};
byte rowPins[ROWS] = {
A4, A5, 13, 12}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
A0, A1, A2, A3
}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char enteredText[8];
char password[8];
int key=-1;
char lastKey;
char var;
boolean passwordEnable=false;
//Buttons for lcd shield
char BT_RIGHT = '4';
char BT_UP = 'a';
char BT_DOWN = 'b';
char BT_LEFT = '6';
char BT_SEL = 'd'; // Ok key
char BT_DEFUSER = 'x'; // not implemented
//leds
int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5;
const int REDLED = 11;
const int GREENLED = 10;
//const int BLUELED = 12;
//mosfet
boolean mosfetEnable = false;
const int mosfet = 1;
//IS VERY IMPORTANT THAT YOU TEST THIS TIME. BY DEFAULT IS IN 1 SEC. THAT IS NOT TOO MUCH. SO TEST IT!
const int MOSFET_TIME = 5000;
//TIME INTS
int GAMEHOURS = 0;
int GAMEMINUTES = 15;
int BOMBMINUTES = 4;
int ACTIVATESECONDS = 5;
boolean endGame = false;
boolean sdStatus = false; //search and destroy game enable used in config
boolean saStatus = false; //same but SAbotaghe
boolean doStatus = false; //for DEmolition
boolean start = true;
// SOUND TONES
boolean soundEnable = true;
int tonepin = 8; // Pin 8 for the sound
int tonoPitido = 3000;
int tonoAlarma1 = 700;
int tonoAlarma2 = 2600;
int tonoActivada = 1330;
int errorTone = 100;
unsigned long iTime;
unsigned long timeCalcVar;
unsigned long redTime;
unsigned long greenTime;
unsigned long iZoneTime;//initial time for zone
byte team=0; // 0 = neutral, 1 = green team, 2 = red team
void setup(){
pinMode(led, OUTPUT);
lcd.begin(16, 2);
// lcd.init(); // initialize the lcd
// lcd.backlight();
lcd.setCursor(2,0);
lcd.print("INITIALIZING");// you can add your team name or someting cool
lcd.setCursor(0,1);
lcd.print("BIOCHEMICAL BOMB");// you can add your team name or someting cool
keypad.setHoldTime(100);
keypad.setDebounceTime(50);
delay(2500);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Be:");// you can add your team name or someting cool
lcd.setCursor(4,1);
lcd.print("Prepared");// you can add your team name or someting cool
keypad.setHoldTime(100);
keypad.setDebounceTime(50);
delay(2500);
pinMode(GREENLED, OUTPUT);
pinMode(REDLED, OUTPUT);
pinMode(mosfet, OUTPUT);
// CONFIGURE THE BARS OF PROGRESS BAR
byte bar1[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
};
byte bar2[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
};
byte bar3[8] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
};
byte bar4[8] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
};
byte bar5[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
byte up[8] = {
B00000,
B00100,
B01110,
B11111,
B11111,
B00000,
B00000,
};
byte down[8] = {
B00000,
B00000,
B11111,
B11111,
B01110,
B00100,
B00000,
};
lcd.createChar(0,bar1);
lcd.createChar(1,bar2);
lcd.createChar(2,bar3);
lcd.createChar(3,bar4);
lcd.createChar(4,bar5);
lcd.createChar(5,up);
lcd.createChar(6,down);
}
void loop(){
menuPrincipal();
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
delay(30);
menuPrincipal();
}
void disarmedSplash(){
if(sdStatus || saStatus){
cls();
lcd.print(" BOMB DISARMED");
lcd.setCursor(0,1);
lcd.print(" GOODS WIN");
digitalWrite(GREENLED, HIGH);
delay(5000);
digitalWrite(GREENLED, LOW);
}
//end code
cls();
lcd.print("Play Again?");
lcd.setCursor(0,1);
lcd.print("A : Yes B : No");
while(1)
{
var = keypad.waitForKey();
if(var == 'a' ){
tone(tonepin,2400,30);
search();
break;
}
if(var == 'b' ){
tone(tonepin,2400,30);
menuPrincipal();
break;
}
}
}
void explodeSplash(){
cls();
delay(100);
lcd.print(" TERRORISTS WIN");
lcd.setCursor(0,1);
lcd.print(" GAME OVER");
for(int i = 200; i>0; i--)// this is the ultra hi definition explosion sound xD
{
tone(tonepin,i);
delay(20);
}
noTone(tonepin);
if(mosfetEnable){
activateMosfet();
}
delay(5000);
cls();
//end code
lcd.print("Play Again?");
lcd.setCursor(0,1);
lcd.print("A : Yes B : No");
while(1)
{
var = keypad.waitForKey();
if(var == 'a' ){
tone(tonepin,2400,30);
//We have two options, search & destroy and sabotaje play again options so!
if(sdStatus){
startGameCount();
search();
}
if(saStatus){
saStatus=true;
startGameCount();
start=true; //to set iTime to actual millis() :D
sabotage();
}
}
if(var == 'b' ){
tone(tonepin,2400,30);
menuPrincipal();
break;
}
}
}