hard core tiny bug

I have checked, double checked, triple checked, rewrote many time the same code. Still, same problem occurs. The thing is, it’s not something very complicated. The same code is use for one thing with different value. while one works, and one doesn’t. Again, I have double checked, triple checked the values too. so can any genius out there help me find out what goes wrong here? thank you so much.

The problem: I have 2 modes, 2 alarms for Flashing 5 led and beeping 1 beeper. mode 3 works as is, but mode 2 works too, but will dimmer led and dimmer beeper. I suspected that the problem is from the timing logic, but don’t think so, checked it many times.

//------------------------------------------------------------------>>Alarm

  if( tempAlarm==1 && bdsoundAlarm==1) {
  digitalWrite(beeperPin, fastSecKey);
  }
  else digitalWrite(beeperPin, LOW);
  
  if( tempAlarm==1  && bdlightAlarm==1) {
      for(int x=1; x<6; x++){
    digitalWrite(ledPin[x], fastSecKey);
     }
     }
     else {
      for(int x=1; x<6; x++){
    digitalWrite(ledPin[x], LOW);
     }
     } 
     
  if(bdFinish==1  && bdsoundAlarm==1) {
  digitalWrite(beeperPin, fastSecKey);
  }
  else digitalWrite(beeperPin, LOW);
  
  if(bdFinish==1  && bdlightAlarm==1) {
      for(int x=1; x<6; x++){
    digitalWrite(ledPin[x], fastSecKey);
     }
     }
     else {
      for(int x=1; x<6; x++){
    digitalWrite(ledPin[x], LOW);
     }
     }  
     
     
   if(timerStart==1 && cdDAY==0 && cdHR==0 && cdMIN==0 && cdSEC==0 && cdsoundAlarm==1) {
  digitalWrite(beeperPin, fastSecKey);
  }
  else digitalWrite(beeperPin, LOW);
  
  if(timerStart==1 && cdDAY==0 && cdHR==0 && cdMIN==0 && cdSEC==0 && cdlightAlarm==1) {
      for(int x=1; x<6; x++){
    digitalWrite(ledPin[x], fastSecKey);
     }
     }
     else {
      for(int x=1; x<6; x++){
    digitalWrite(ledPin[x], LOW);
     }
     }  
  

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Alarm
 if(bdSEC>10 && shuntMa<50)bdFinish=1;

else{
 bdFinish=0;
}

 
//------------------------------------------------------------------>>Time
unsigned long currentSec=millis();
if(currentSec-previousSec>1000) {
SEC++; 
secKey=!secKey;
previousSec=currentSec;

if(shuntMa>50){
shuntMatotal=shuntMatotal+shuntMa;
bdSEC++;
}


   if(timerStart==1) {arrowrighLoc++;} 

    if(timerStart==1){
    if(cdDAY==0 && cdHR==0 && cdMIN==0 && cdSEC==0)cdSEC=cdSEC;
    else {
      cdSEC=cdSEC-1;
    }
    }
   else cdSEC=cdSEC;


 
 
  
}

//----------------------------
unsigned long currentSecSec=millis();
   if(currentSecSec-previousSecSec>200) {
   fastSecKey=!fastSecKey;
  
   previousSecSec=currentSecSec;  
   }



//------------------------------------------------------------------>> Sensors
// 8% difference from meter to arduino reading
int shuntVal= analogRead(shuntPin);
shuntMa=shuntVal*(5.0/1023.0*1000.0*0.92);              //shuntMa
shuntMah=shuntMatotal/3600;                            //shuntMah

//(21%) tempVal*0.2=F degree/ (F-32)X5/9=C degree 
int tempVal= analogRead(tempPin);
tempF=tempVal*0.21;                    // tempF
tempC=(tempF-32)*5/9;                      // tempC

if(tempC > tempAlarmValue) tempAlarm=1;
else tempAlarm=0;

//darkest 50-1010 lightest
int lightVal= analogRead(lightPin);
lightVal=map(lightVal, 50,1010,0,999);
lightLevel=constrain (lightVal, 0, 999);             // lightLevel

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Sensors

1 Post ALL your code.

2 Clean up your code!. Use the auto formatter in the ide

  1. What do you want it to do and what does it do

Mark

holmes4:
1 Post ALL your code.

it does what I want it to do, but with dimmer led brightness and lower beeper sound.

part 1:

#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,6,7);

byte timeIcon[8] = {
  0b11111,
  0b10001,
  0b01010,
  0b00100,
  0b00100,
  0b01010,
  0b10001,
  0b11111};

byte tempIcon[8] = {
  0b00100,
  0b01011,
  0b01010,
  0b01011,
  0b01110,
  0b11111,
  0b11111,
  0b01110};

byte batteryIcon[8] = {
  0b01110,
  0b11011,
  0b10001,
  0b11111,
  0b10001,
  0b11111,
  0b11111,
  0b00000};

byte lightIcon[8] = {
  0b00000,
  0b10101,
  0b01110,
  0b11011,
  0b01110,
  0b10101,
  0b00100,
  0b00000};

byte arrowupIcon[8] = {
  0b00100,
  0b00100,
  0b01110,
  0b11111,
  0b00100,
  0b01110,
  0b01110,
  0b01010};

byte buttonIcon[8] = {
  0b00000,
  0b01010,
  0b01010,
  0b00000,
  0b10101,
  0b10001,
  0b01110,
  0b00000};

byte alarmIcon[8] = {
  0b00000,
  0b00100,
  0b01110,
  0b01110,
  0b01110,
  0b11111,
  0b00100,
  0b00000
};

int timeI=0;
int tempI=1;
int batteryI=2;   
int lightI=3; 
int arrowupI=4;   
int buttonI=5;  
int alarmI=6;  


#define tempI char(0x01)
#define batteryI char(0x02)   
#define lightI char(0x03) 
#define arrowupI char(0x04)   
#define buttonI char(0x05)
#define alarmI char(0x06)
#define timeI char(0x07)
//===================

// Pinouts =====>
int buttonPin[6]={
  0,A4,A3,A2,A1}; // Button 1-4
int ledPin[7]={
  0,8,9,10,11,12};   // Led 1-5
int shuntPin=A5;               
int tempPin=A6; 
int lightPin=A7;
int beeperPin=A0;


// TimeValues  ======>
int DAY=0; //Day
int HR=0; //hour
int MIN=0; //minute
int SEC=0;//Second
int lastSec=0;
unsigned long previousSec=0;
unsigned long previousSecSec=0;

int bdHR=0; // hour
int bdMIN=0; //minute
int bdSEC=0; //Second

int cdDAY=0; // days 
int cdHR=0; // hour
int cdMIN=0; //minute
int cdSEC=0; //Second

int secKey=0;
int fastSecKey=0;
int timerStart=0;

//   ======> sensorValues
int shuntMa=0;
int shuntMaup=0;
int shuntMah=0;
int shuntWh=0;
unsigned long shuntMatotal=0;
int tempF=0;
int tempC=0;
int tempAlarm=0;
int tempAlarmValue=50;
int lightLevel=0;
int lightLevelup=0;

int bdFinish=0;

//   ======> menus
int mode=1;
int lastMode=1;
int arrowLoc=0;
int toggleCF=0;
int bdsoundAlarm=1;
int bdlightAlarm=1;
int arrowrighLoc=0;

int cdsoundAlarm=1;
int cdlightAlarm=1;
//   ======> button
int buttonState[5]={
  0,0,0,0,0};
int lastButtonState[5]={
  0,1,1,1,1};
int buttonPress[5]={
  0,0,0,0,0};
int lastButtonPress[5]={
  0,0,0,0,0};
//   ======>


//=============

void setup() {


  //===5 RED LEDs ===
  for(int x=1; x<7; x++){
    pinMode(ledPin[x],OUTPUT);
  }  
  //===4 Black buttons ===  
  for(int x=1; x<5; x++){
    pinMode(buttonPin[x], INPUT_PULLUP);
  }  
  //===Sensors ===
  pinMode(shuntPin, INPUT);// shunt voltage   
  pinMode(tempPin, INPUT);// Temp. Sensor  
  pinMode(lightPin, INPUT);// Light resistor   
  pinMode(beeperPin, OUTPUT); // Beeper  

  //===LCD SETUP ===  
  lcd.begin(16,2);
  lcd.createChar(7, timeIcon);
  lcd.createChar(1, tempIcon);
  lcd.createChar(2, batteryIcon);   
  lcd.createChar(3, lightIcon);  
  lcd.createChar(4, arrowupIcon);   
  lcd.createChar(5, buttonIcon);  
  lcd.createChar(6, alarmIcon);  

}

//================
void loop() {




  //------------------->>LCD 
  if(mode!=lastMode){
    if(arrowLoc>=1){
      arrowLoc=0;
      mode--;
    }
    lastMode=mode;
  }

  //======================

  if(mode==1){

    char x [16];
    sprintf(x, "%c %02d:%02d:%02d:%02d  %c", buttonI,DAY,HR,MIN,SEC,buttonI); 
    lcdPrintText(0,0,x);

    if(arrowLoc==0){
      if(mode==1&&toggleCF==0){

        if(fastSecKey==1){  
          char C [7];
          sprintf(C, "%003d%c %02d%c",lightLevel, lightI, tempC,tempI); 
          lcdPrintText(8,1,C);  
        }
      }
      else{
        if(fastSecKey==1){  
          char F [7];
          sprintf(F, "%003d%c %02d%c",lightLevel, lightI, tempF,tempI); 
          lcdPrintText(8,1,F);    
        }
      }
    }

    //---------------------------

    if(mode==1&&arrowLoc==-1)arrowLoc=5;  

    if(mode==1&&arrowLoc==0){
      char y [16];
      sprintf(y, "[Clock] ");
      lcdPrintText(0,1,y);  
    }    

    if(mode==1&&arrowLoc==1){
      char y [16];
      sprintf(y, "   %cDay               ", arrowupI );
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          DAY++;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }

    if(mode==1&&arrowLoc==2){
      char y [16];
      sprintf(y, "      %cHour           ", arrowupI );
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          HR++;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }     

    if(mode==1&&arrowLoc==3){
      char y [16];
      sprintf(y, "   Minute%c          ", arrowupI );
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          MIN++;
        }
      }
      lastButtonPress[4]=buttonPress[4];
    }     

    if(mode==1&&arrowLoc==4){
      char y [16];
      sprintf(y, "         Sec%c       ", arrowupI );
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          SEC=0;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }     

    if(mode==1&&arrowLoc==5){

      char y [16];
      sprintf(y, " <Toggle C/F:%1d>        " , toggleCF );
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          toggleCF=!toggleCF;
        }
      }
      lastButtonPress[4]=buttonPress[4];  
    }   

    if(mode==1&&arrowLoc==6)arrowLoc=0;  

  }

  //===========================
  if(mode==2){  

    char x [16];
    sprintf(x, "%c%02d:%02d:%02d%c", batteryI,bdHR,bdMIN,bdSEC,batteryI); 
    lcdPrintText(0,0,x);

    if(mode==2&&toggleCF==0){
      char C [4];
      sprintf(C, " %02d ", tempC); 
      lcdPrintText(10,0,C);  
    }
    else{
      char F [4];
      sprintf(F, " %02d ", tempF); 
      lcdPrintText(10,0,F);    
    }  

    if(mode==2&&bdsoundAlarm==1){
      char SA [3];
      sprintf(SA, "%c", alarmI); 
      lcdPrintText(14,0,SA);  
    }
    else{
      char SA [3];
      sprintf(SA, " "); 
      lcdPrintText(14,0,SA);    
    }    

    if(mode==2&&bdlightAlarm==1){
      char LA [3];
      sprintf(LA, "%c", lightI); 
      lcdPrintText(15,0,LA);  
    }
    else{
      char LA [3];
      sprintf(LA, " "); 
      lcdPrintText(15,0,LA);    
    }      

    //-----------------------

    if(mode==2&&arrowLoc==-1)arrowLoc=5;

    if(mode==2&&arrowLoc==0){
      if(fastSecKey==1){
        char y [16];
        sprintf(y, "%04d:mA",shuntMa );
        lcdPrintText(9,1,y);  
      }


      if(shuntMah>1){
        char y [16];
        sprintf(y, "%04d:mAh ",shuntMah );
        lcdPrintText(0,1,y);  
      } 

      else lcdPrintText(0,1,"[Tester] ");

    } 


    if(mode==2&&arrowLoc==1){
      char y [16];
      sprintf(y, "  <Reset>              " );
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          shuntMatotal=0;    
          shuntMah=0;
          shuntMa=0;
          bdSEC=0;
          bdMIN=0;
          bdHR=0;
          bdFinish=0;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }


    if(mode==2&&arrowLoc==2){
      char y [16];
      sprintf(y, "<Alarm Temp:%02dC>    ", tempAlarmValue);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          tempAlarmValue = tempAlarmValue+10;
          if(tempAlarmValue==100)tempAlarmValue=30;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }  


    if(mode==2&&arrowLoc==3){
      char y [16];
      sprintf(y, " Toggle C/F %c     ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          toggleCF=!toggleCF;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }  


    if(mode==2&&arrowLoc==4){
      char y [16];
      sprintf(y, "   Sound Alarm%c   ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          bdsoundAlarm=!bdsoundAlarm;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }    

    if(mode==2&&arrowLoc==5){
      char y [16];
      sprintf(y, "    Light Alarm%c ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          bdlightAlarm=!bdlightAlarm;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }  

    if(mode==2&&arrowLoc==6)arrowLoc=0;
  }

  //==============

  if(mode==3){

part2:

  //==============

  if(mode==3){

    char x [16];
    sprintf(x, "%c%02d:%02d:%02d:%02d%c %c%c% ", timeI, cdDAY,cdHR,cdMIN,cdSEC,timeI, alarmI,lightI); 
    lcdPrintText(0,0,x);

    if(mode==3&&cdsoundAlarm==1){
      char SA [3];
      sprintf(SA, "%c", alarmI); 
      lcdPrintText(14,0,SA);  
    }
    else{
      char SA [3];
      sprintf(SA, " "); 
      lcdPrintText(14,0,SA);    
    }    

    if(mode==3&&cdlightAlarm==1){
      char LA [3];
      sprintf(LA, "%c", lightI); 
      lcdPrintText(15,0,LA);  
    }
    else{
      char LA [3];
      sprintf(LA, " "); 
      lcdPrintText(15,0,LA);    
    }      

    //----------------
    if(mode==3&&arrowLoc==-1)arrowLoc=7;
    //----------------

    if(mode==3&&arrowLoc==0){
      if(timerStart==0){
        lcdPrintText(0,1,"[Timer]  <Start>");    
      }

      else{  
        lcdPrintText(7,1,"  <Pause>");           
        lcdPrintText(arrowrighLoc,1, " >>");            

      }

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          timerStart=!timerStart;
        }
      }
      lastButtonPress[4]=buttonPress[4];  
    }    



    if(mode==3&&arrowLoc==1){
      char y [16];
      sprintf(y, "  <Reset>           ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          cdDAY=0;
          cdHR=0;
          cdMIN=0;
          cdSEC=0;
          timerStart=0;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }  

    if(mode==3&&arrowLoc==2){
      char y [16];
      sprintf(y, "  %cDay               ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          cdDAY++;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }  

    if(mode==3&&arrowLoc==3){
      char y [16];
      sprintf(y, "     %cHour           ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          cdHR++;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }    



    if(mode==3&&arrowLoc==4){
      char y [16];
      sprintf(y, "        %cMinute          ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          cdMIN++;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }      


    if(mode==3&&arrowLoc==5){
      char y [16];
      sprintf(y, "           %cSec     ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          cdSEC++;
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }  


    if(mode==3&&arrowLoc==6){
      char y [16];
      sprintf(y, "   Sound Alarm%c   ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          cdsoundAlarm=!cdsoundAlarm; 
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }      


    if(mode==3&&arrowLoc==7){
      char y [16];
      sprintf(y, "    Light Alarm%c ", arrowupI);
      lcdPrintText(0,1,y);  

      if(buttonPress[4]!=lastButtonPress[4]){
        if(buttonPress[4]==HIGH){
          cdlightAlarm=!cdlightAlarm;  
        }
      }
      lastButtonPress[4]=buttonPress[4];

    }        




    if(mode==3&&arrowLoc==8)arrowLoc=0;
  }


  //=========================
  if(mode==4)mode=1;



  //<<<<<<<<<<<<<<<<<LCD



  //-------------------->>Alarm

  if( tempAlarm==1 && bdsoundAlarm==1) {
    digitalWrite(beeperPin, fastSecKey);
  }
  else digitalWrite(beeperPin, LOW);

  if( tempAlarm==1  && bdlightAlarm==1) {
    for(int x=1; x<6; x++){
      digitalWrite(ledPin[x], fastSecKey);
    }
  }
  else {
    for(int x=1; x<6; x++){
      digitalWrite(ledPin[x], LOW);
    }
  } 

  if(bdFinish==1  && bdsoundAlarm==1) {
    digitalWrite(beeperPin, fastSecKey);
  }
  else digitalWrite(beeperPin, LOW);

  if(bdFinish==1  && bdlightAlarm==1) {
    for(int x=1; x<6; x++){
      digitalWrite(ledPin[x], fastSecKey);
    }
  }
  else {
    for(int x=1; x<6; x++){
      digitalWrite(ledPin[x], LOW);
    }
  }  


  if(timerStart==1 && cdDAY==0 && cdHR==0 && cdMIN==0 && cdSEC==0 && cdsoundAlarm==1) {
    digitalWrite(beeperPin, fastSecKey);
  }
  else digitalWrite(beeperPin, LOW);

  if(timerStart==1 && cdDAY==0 && cdHR==0 && cdMIN==0 && cdSEC==0 && cdlightAlarm==1) {
    for(int x=1; x<6; x++){
      digitalWrite(ledPin[x], fastSecKey);
    }
  }
  else {
    for(int x=1; x<6; x++){
      digitalWrite(ledPin[x], LOW);
    }
  }  


  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Alarm
  if(bdSEC>10 && shuntMa<50)bdFinish=1;

  else{
    bdFinish=0;
  }


  //--------------------->>Time
  unsigned long currentSec=millis();
  if(currentSec-previousSec>1000) {
    SEC++; 
    secKey=!secKey;
    previousSec=currentSec;

    if(shuntMa>50){
      shuntMatotal=shuntMatotal+shuntMa;
      bdSEC++;
    }


    if(timerStart==1) {
      arrowrighLoc++;
    } 

    if(timerStart==1){
      if(cdDAY==0 && cdHR==0 && cdMIN==0 && cdSEC==0)cdSEC=cdSEC;
      else {
        cdSEC=cdSEC-1;
      }
    }
    else cdSEC=cdSEC;





  }

  //----------------------------
  unsigned long currentSecSec=millis();
  if(currentSecSec-previousSecSec>200) {
    fastSecKey=!fastSecKey;

    previousSecSec=currentSecSec;  
  }




  if(arrowrighLoc==7) arrowrighLoc=0;  

  if(cdSEC==-1){
    cdSEC=59; 
    cdMIN--;
  }
  if(cdMIN==-1){
    cdMIN=59; 
    cdHR--;
  }
  if(cdHR==-1){
    cdHR=23; 
    cdDAY--;
  }

  if(cdSEC==60){
    cdSEC=0; 
    cdMIN++;
  }
  if(cdMIN==60){
    cdMIN=0; 
    cdHR++;
  }
  if(cdHR==24){
    cdHR=0; 
    cdDAY++;
  }

  if(bdSEC==60){
    bdSEC=0; 
    bdMIN++;
  }
  if(bdMIN==60){
    bdMIN=0; 
    bdHR++;
  }

  if(SEC==60){
    SEC=0; 
    MIN++;
  }
  if(MIN==60){
    MIN=0; 
    HR++;
  }
  if(HR==24) {
    HR=0;
    DAY++;
  }
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<Time


  //------------------->> Sensors
  // 8% difference from meter to arduino reading
  int shuntVal= analogRead(shuntPin);
  shuntMa=shuntVal*(5.0/1023.0*1000.0*0.92);              //shuntMa
  shuntMah=shuntMatotal/3600;                            //shuntMah

  //(21%) tempVal*0.2=F degree/ (F-32)X5/9=C degree 
  int tempVal= analogRead(tempPin);
  tempF=tempVal*0.21;                    // tempF
  tempC=(tempF-32)*5/9;                      // tempC

  if(tempC > tempAlarmValue) tempAlarm=1;
  else tempAlarm=0;

  //darkest 50-1010 lightest
  int lightVal= analogRead(lightPin);
  lightVal=map(lightVal, 50,1010,0,999);
  lightLevel=constrain (lightVal, 0, 999);             // lightLevel

  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Sensors

  //------------------------------>> Buttons

  //--------------------
  if(buttonPress[1]!=lastButtonPress[1]){
    if(buttonPress[1]==HIGH){
      mode++;
    }
  }
  lastButtonPress[1]=buttonPress[1];

  //-------------------
  if(buttonPress[2]!=lastButtonPress[2]){
    if(buttonPress[2]==HIGH){
      arrowLoc--; 
    }
  }
  lastButtonPress[2]=buttonPress[2];

  //-------------------
  if(buttonPress[3]!=lastButtonPress[3]){
    if(buttonPress[3]==HIGH){
      arrowLoc++;
    }
  }
  lastButtonPress[3]=buttonPress[3];

  //-------------------
  if(buttonPress[4]!=lastButtonPress[4]){
    if(buttonPress[4]==HIGH){

    }
  }
  lastButtonPress[4]=buttonPress[4];

  //--------------------

  for(int x=1; x<5; x++){  
    buttonState[x]=digitalRead(buttonPin[x]);

    if(buttonState[x]!=lastButtonState[x]){
      lastButtonState[x]=buttonState[x];
      if(buttonState[x]==LOW)buttonPress[x]=1;
      else buttonPress[x]=0;
    }

  } 

  //<<<<<<<<<<<<<<<<<<<<<<<<< Buttons


}


//=============>>FUNCTIONS


void lcdPrintText (int x, int y, char* text){

  lcd.setCursor(x,y);  
  lcd.print(text);
}

Example of why you must post all the code

int buttonPin[6]={
  0,A4,A3,A2,A1}; // Button 1-4
int ledPin[7]={
  0,8,9,10,11,12};   // Led 1-5

Why are you using pin 0 as a button an input, a led an output and for Serial!

Array are numbered from 0 use them that way!

Mark

holmes4: Example of why you must post all the code

int buttonPin[6]={
  0,A4,A3,A2,A1}; // Button 1-4
int ledPin[7]={
  0,8,9,10,11,12};   // Led 1-5

Why are you using pin 0 as a button an input, a led an output and for Serial!

Array are numbered from 0 use them that way!

Mark

I simply ignore array 0; buttonPin[1]= button 1; buttonPin[2]= button 2;

ledPin[5]=led5;

this way, I don't get confused.

  //===5 RED LEDs ===
  for(int x=1; x<7; x++){
    pinMode(ledPin[x],OUTPUT);
  }

Five or six? What value is ledPin[6]?

    char x [16];
    sprintf(x, "%c %02d:%02d:%02d:%02d  %c", buttonI,DAY,HR,MIN,SEC,buttonI);

Space for the terminator?

          char C [7];
          sprintf(C, "%003d%c %02d%c",lightLevel, lightI, tempC,tempI);

Space for the entire string? Is "00" a valid specifier?

          char F [7];
          sprintf(F, "%003d%c %02d%c",lightLevel, lightI, tempF,tempI);

Ditto.

Have you checked for SRAM free space?

      char y [16];
      sprintf(y, "      %cHour           ", arrowupI );

Not even close.

      char y [16];
      sprintf(y, "   Minute%c          ", arrowupI );

Ditto.

      char y [16];
      sprintf(y, "         Sec%c       ", arrowupI );
      char y [16];
      sprintf(y, " <Toggle C/F:%1d>        " , toggleCF );
      char C [4];
      sprintf(C, " %02d ", tempC);
      char F [4];
      sprintf(F, " %02d ", tempF);
      char y [16];
      sprintf(y, "  <Reset>              " );
      char y [16];
      sprintf(y, "<Alarm Temp:%02dC>    ", tempAlarmValue);

Ditto *6… Enough of that. You can figure out the rest on your own.

if(currentSec-previousSec >= 1000) {

previousSec += 1000;

shuntMa=shuntVal*(5.0 / 1024.0 1000.00.92); //shuntMa

it’s 5. thanks for locating this for me. value ledPin[6] should be some random number.

[quote author=Coding Badly link=topic=257671.msg1821970#msg1821970 date=1406603736]

          char C [7];
          sprintf(C, "%003d%c %02d%c",lightLevel, lightI, tempC,tempI);

Space for the entire string? Is "00" a valid specifier? [/quote]

space for my 16x2 LCD. It got to have space, to space out the info to the location I want.

I see. 0-1023= 1024 points.

[quote author=Coding Badly link=topic=257671.msg1821973#msg1821973 date=1406603816]

Have you checked for SRAM free space? [/quote]

no. don't know how to check it, and never think of checking it. is it a problem?