Go Down

Topic: Stuck on program (Read 2444 times) previous topic - next topic

aaron361068

Jun 30, 2013, 09:10 am Last Edit: Jun 30, 2013, 09:13 am by Coding Badly Reason: 1
this is my first real project and im a bit stuck

I have a jeep that has a lot of broken/added electronics and the diver seat is starting to look like a spacecraft do to all the extra switches.

so my plan is to have a 2X16 LCD Screen and a 8 channel relay  nd two push buttons to do all the work.  

i got it started but im kinda stuck. i want to add a feature of having some of the items like the radio go off with the accessories or on all the time depending on what i want. i think i have a start with this program but i might be way off base.

i havent figured out how to make a detector to see if the accessory on the jeep is on and then implement them.

There is a strong possibility that i might be way over my head on this..... hahaa


Code: [Select]
const int pushButtonPin = 2;
const int selector = 12;
int pressCount = 0;
int selectCount = 0;
int windshieldstatus = 1;
int frontlightsstatus = 10;
int rearlightstatus = 11;
int radiostatus = 13;
int flashlightstatus = A1;
int hamstatus = A2;
int antennaup = A3;
int antennadown = A4;

int prevState = LOW;
int currState;

int prevState2 = LOW;
int currState2;

#include <Wire.h>
#include <LiquidCrystal.h>   // include LCD library


#define LCD_BACKLIGHT_OFF()     digitalWrite( LCD_BACKLIGHT_PIN, LOW )
#define LCD_BACKLIGHT_ON()      digitalWrite( LCD_BACKLIGHT_PIN, HIGH )
#define LCD_BACKLIGHT(state)    { if( state ){digitalWrite( LCD_BACKLIGHT_PIN, HIGH );}else{digitalWrite( LCD_BACKLIGHT_PIN, LOW );} }

byte buttonJustPressed  = false;         //this will be true after a ReadButtons() call if triggered
byte buttonJustReleased = false;         //this will be true after a ReadButtons() call if triggered


LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

int lastpresscount = 0;

int windshieldmode = 0;
int frontlightsmode = 0;
int rearlightmode = 0;
int radiomode = 0;
int flashlightmode = 0;
int hammode = 0;





void setup()
{
 
  lcd.begin( 16, 2 );
 
  lcd.setCursor( 1, 0 );  

  lcd.print( "SCOUT CONTROL" );
  //
  lcd.setCursor( 5, 1 );

  lcd.print( "Ready" );

pinMode(pushButtonPin, INPUT);
  digitalRead(pushButtonPin);

pinMode(selector, INPUT);
  digitalRead(selector);
 
pinMode(windshieldstatus, OUTPUT);
pinMode(frontlightsstatus, OUTPUT);
pinMode(rearlightstatus, OUTPUT);
pinMode(radiostatus , OUTPUT);
pinMode(flashlightstatus , OUTPUT);
pinMode(hamstatus , OUTPUT);
pinMode(antennaup, OUTPUT);
pinMode(antennadown, OUTPUT);

Serial.begin(9600);


}










void loop()
{
 

 
  currState = digitalRead(pushButtonPin);
 if (currState != prevState)
 {
   if (currState == HIGH)
   {
     pressCount++;
 
   }
   delay(10);
 }
 prevState = currState;
 
    currState2 = digitalRead(selector);
 if (currState2 != prevState2)
 {
   if (currState2 == HIGH)
   {
      selectCount++;
   }
   delay(100);
 }
 prevState2 = currState2;
 
 
 
if(pressCount > 9) {pressCount = 0;}
 
if(pressCount != lastpresscount){
 
if(pressCount == 1){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("windsheild");
 lcd.setCursor(0,1);
 lcd.print("Mode:");
selectCount = windshieldmode;
 
}
if(pressCount == 2){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("frontlights");
 lcd.setCursor(0,1);
 lcd.print("Mode:");
 selectCount = frontlightsmode;  
}
if(pressCount == 3){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("rearlight");
 lcd.setCursor(0,1);
 lcd.print("Mode:");
 selectCount = rearlightmode;  
}
if(pressCount == 4){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("radio");
 lcd.setCursor(0,1);
 lcd.print("Mode:");
 selectCount = radiomode;  
}
if(pressCount == 5){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("flashlight");
 lcd.setCursor(0,1);
 lcd.print("Mode:");
 selectCount = flashlightmode;  
}
if(pressCount == 6){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("HAM");
 lcd.setCursor(0,1);
 lcd.print("Mode:");
 selectCount = hammode;  
}
/* if(pressCount == 7){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Antenna");  
 lcd.setCursor(0,1);
 lcd.print("Mode:");
 selectCount = antennamode;
} */
if(pressCount == 0){
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Scout Control");

}
}

Serial.println(selectCount);


if(pressCount == 1){
 if(selectCount == 0){
   lcd.setCursor(7,1);
   lcd.print("OFF");
   digitalWrite(windshieldstatus,LOW);  
   }
 if(selectCount == 1){
   lcd.setCursor(7,1);
   lcd.print(" ON");
   digitalWrite(windshieldstatus,HIGH);
 }
 if(selectCount > 1)
   {selectCount = 0;}
   
windshieldmode = selectCount;
}
if(pressCount == 2){
 if(selectCount == 0){
   lcd.setCursor(7,1);
   lcd.print("OFF");
   digitalWrite(frontlightsstatus ,LOW);  
   }
 if(selectCount == 2){
   lcd.setCursor(7,1);
   lcd.print(" ON");
   digitalWrite(frontlightsstatus ,HIGH);
 }
 if(selectCount > 1)
   {selectCount = 0;}
   
frontlightsmode = selectCount;
}

if(pressCount == 3){
 if(selectCount == 0){
   lcd.setCursor(7,1);
   lcd.print("OFF");
   digitalWrite(rearlightstatus ,LOW);  
   }
 if(selectCount == 2){
   lcd.setCursor(7,1);
   lcd.print(" ON");
   digitalWrite(rearlightstatus ,HIGH);
 }
 if(selectCount > 1)
   {selectCount = 0;}
   
rearlightmode = selectCount;
}

if(pressCount == 4){
 if(selectCount == 0){
   lcd.setCursor(7,1);
   lcd.print("OFF");
   digitalWrite(radiostatus ,LOW);  
   }
 if(selectCount == 2){
   lcd.setCursor(7,1);
   lcd.print(" ON");
   digitalWrite(radiostatus ,HIGH);
 }
 if(selectCount > 1)
   {selectCount = 0;}
   
radiomode = selectCount;
}

if(pressCount == 5){
 if(selectCount == 0){
   lcd.setCursor(7,1);
   lcd.print("OFF");
   digitalWrite(flashlightstatus ,LOW);  
   }
 if(selectCount == 2){
   lcd.setCursor(7,1);
   lcd.print(" ON");
   digitalWrite(flashlightstatus ,HIGH);
 }
 if(selectCount > 1)
   {selectCount = 0;}
   
flashlightmode = selectCount;
}

if(pressCount == 6){
 if(selectCount == 0){
   lcd.setCursor(7,1);
   lcd.print("OFF");
   digitalWrite(hamstatus ,LOW);  
   }
 if(selectCount == 2){
   lcd.setCursor(7,1);
   lcd.print(" ON");
   digitalWrite(hamstatus ,HIGH);
 }
 if(selectCount > 1)
   {selectCount = 0;}
   
hammode = selectCount;
}

if(pressCount == 7){
  if(selectCount == 0){
  lcd.setCursor(7,1);
  lcd.print("OFF");
  digitalWrite(frontlightsstatus ,LOW);  
   }
 if(selectCount == 2){
   lcd.setCursor(7,1);
   lcd.print(" ON");
   digitalWrite(frontlightsstatus ,HIGH);
 }
 if(selectCount > 1)
   {selectCount = 0;}
   
frontlightsmode = selectCount;
}


lastpresscount = pressCount;

}



Moderator edit: [code] [/code] tags added.

AWOL

Did you have a question?

aaron361068

Yes, sorry if I was not clear. 

How do I make it so that I have an option to make a device only go on when the jeeps accessories are on so I will not kill the battery, or always on or always off.

AWOL

Can I suggest a code tidy-up before you add any features?
You have stuff Iike this
Code: [Select]
int frontlightsstatus = 10; which is difficult to tell of it is an input pin designator, or an actual status.
Pin designators should be byte constants.

A trip through the code auto-format would be welcome too.

aaron361068

Thank you ill work on that and get back.

nicoverduin

While you are at it, some more comments helps :)...does not cost any more code. :)
Met vriendelijke groet / kindest regards
Nico Verduin
www.verelec.nl
Do not PM me for personal consultancy unless you are willing to pay for it.

aaron361068

ok i changed some things. what do you think now

Code: [Select]
const int pushButtonPin = 2;  //button that will swithch between modes, like windsheld wippers, and rearlight
const int selector = 12;   // button that will change the settings of each modewindshieldpower
int pressCount = 0;
int selectCount = 0;
int windshieldpower = 1;  // i want this to be able have to ability to be on / off / and intermittently on so that
int frontlightspower = 10;
int rearlightpower = 11;
int radiopower = 13;
int flashlightpower = A1;
int hampower = A2;
int antennaup = A3; //antenna up and down is seperate because the factory motor has a seperate wire for moving up and moving down
int antennadown = A4;

int prevState = LOW; //part of debounce/counter for the mode button
int currState;

int prevState2 = LOW; //part of dedbounce/ coutner for the selector button
int currState2;

#include <Wire.h>
#include <LiquidCrystal.h>   // include LCD library


#define LCD_BACKLIGHT_OFF()     digitalWrite( LCD_BACKLIGHT_PIN, LOW )
#define LCD_BACKLIGHT_ON()      digitalWrite( LCD_BACKLIGHT_PIN, HIGH )
#define LCD_BACKLIGHT(state)    { if( state ){digitalWrite( LCD_BACKLIGHT_PIN, HIGH );}else{digitalWrite( LCD_BACKLIGHT_PIN, LOW );} }

byte buttonJustPressed  = false;         //this will be true after a ReadButtons() call if triggered
byte buttonJustReleased = false;         //this will be true after a ReadButtons() call if triggered


LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

int lastpresscount = 0;

int windshieldmode = 0;
int frontlightsmode = 0;
int rearlightmode = 0;
int radiomode = 0;
int flashlightmode = 0;
int hammode = 0;





void setup()
{

  lcd.begin( 16, 2 );

  lcd.setCursor( 1, 0 );   

  lcd.print( "SCOUT CONTROL" );
  //
  lcd.setCursor( 5, 1 );

  lcd.print( "Ready" );

  pinMode(pushButtonPin, INPUT);
  digitalRead(pushButtonPin);

  pinMode(selector, INPUT);
  digitalRead(selector);

  pinMode(windshieldpower, OUTPUT);
  pinMode(frontlightspower, OUTPUT);
  pinMode(rearlightpower, OUTPUT);
  pinMode(radiopower , OUTPUT);
  pinMode(flashlightpower , OUTPUT);
  pinMode(hampower , OUTPUT);
  pinMode(antennaup, OUTPUT);
  pinMode(antennadown, OUTPUT);

  Serial.begin(9600);


}










void loop()
{



  currState = digitalRead(pushButtonPin);
  if (currState != prevState)
  {
    if (currState == HIGH)
    {
      pressCount++;

    }
    delay(10);
  }
  prevState = currState;

  currState2 = digitalRead(selector);
  if (currState2 != prevState2)
  {
    if (currState2 == HIGH)
    {
      selectCount++;
    }
    delay(100);
  }
  prevState2 = currState2;



  if(pressCount > 9) {
    pressCount = 0;
  }

  if(pressCount != lastpresscount){

    if(pressCount == 1){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("windsheild");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = windshieldmode;

    }
    if(pressCount == 2){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("frontlights");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = frontlightsmode; 
    }
    if(pressCount == 3){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("rearlight");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = rearlightmode;   
    }
    if(pressCount == 4){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("radio");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = radiomode;   
    }
    if(pressCount == 5){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("flashlight");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = flashlightmode; 
    }
    if(pressCount == 6){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("HAM");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = hammode; 
    }
    /* if(pressCount == 7){                  not using this yet
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Antenna"); 
     lcd.setCursor(0,1);
     lcd.print("Mode:");
     selectCount = antennamode;
     } */
    if(pressCount == 0){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Scout Control");

    }
  }

  Serial.println(selectCount);


  if(pressCount == 1){
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(windshieldpower,LOW); 
    }
    if(selectCount == 1){
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(windshieldpower,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    windshieldmode = selectCount;
  }
  if(pressCount == 2){
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(frontlightspower ,LOW); 
    }
    if(selectCount == 2){
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(frontlightspower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    frontlightsmode = selectCount;
  }

  if(pressCount == 3){
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(rearlightpower ,LOW); 
    }
    if(selectCount == 2){
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(rearlightpower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    rearlightmode = selectCount;
  }

  if(pressCount == 4){
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(radiopower ,LOW); 
    }
    if(selectCount == 2){
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(radiopower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    radiomode = selectCount;
  }

  if(pressCount == 5){
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(flashlightpower ,LOW); 
    }
    if(selectCount == 2){
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(flashlightpower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    flashlightmode = selectCount;
  }

  if(pressCount == 6){
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(hampower ,LOW); 
    }
    if(selectCount == 2){
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(hampower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    hammode = selectCount;
  }

  if(pressCount == 7){
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(frontlightspower ,LOW); 
    }
    if(selectCount == 2){
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(frontlightspower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    frontlightsmode = selectCount;
  }


  lastpresscount = pressCount;

}


Arrch

I think you have a ridiculous amount of white space between globals and setup, as well as between setup and loop. I also think you should be more consistent with your curly braces: either have them on separate lines (recommended):

Code: [Select]
if (someCondition)
{
  // code here
}


or on the same line as the if statement, but with a space between the end of the statement and the brace:

Code: [Select]
if (someCondition) {
  // code here
}

aaron361068

more changes, im learning slowly but surely
Code: [Select]
const int pushButtonPin = 2;  //button that will swithch between modes, like windsheld wippers, and rearlight
const int selector = 12;   // button that will change the settings of each modewindshieldpower
int pressCount = 0;
int selectCount = 0;
int windshieldpower = 1;  // i want this to be able have to ability to be on / off / and intermittently on so that
int frontlightspower = 10;
int rearlightpower = 11;
int radiopower = 13;
int flashlightpower = A1;
int hampower = A2;
int antennaup = A3; //antenna up and down is seperate because the factory motor has a seperate wire for moving up and moving down
int antennadown = A4;

int prevState = LOW; //part of debounce/counter for the mode button
int currState;

int prevState2 = LOW; //part of dedbounce/ coutner for the selector button
int currState2;

#include <Wire.h>
#include <LiquidCrystal.h>   // include LCD library


#define LCD_BACKLIGHT_OFF()     digitalWrite( LCD_BACKLIGHT_PIN, LOW )
#define LCD_BACKLIGHT_ON()      digitalWrite( LCD_BACKLIGHT_PIN, HIGH )
#define LCD_BACKLIGHT(state)    { if( state ){digitalWrite( LCD_BACKLIGHT_PIN, HIGH );}else{digitalWrite( LCD_BACKLIGHT_PIN, LOW );} }

byte buttonJustPressed  = false;         //this will be true after a ReadButtons() call if triggered
byte buttonJustReleased = false;         //this will be true after a ReadButtons() call if triggered


LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

int lastpresscount = 0;

int windshieldmode = 0;
int frontlightsmode = 0;
int rearlightmode = 0;
int radiomode = 0;
int flashlightmode = 0;
int hammode = 0;


void setup()
{

  lcd.begin( 16, 2 );

  lcd.setCursor( 1, 0 );   

  lcd.print( "SCOUT CONTROL" );
  //
  lcd.setCursor( 5, 1 );

  lcd.print( "Ready" );

  pinMode(pushButtonPin, INPUT);
  digitalRead(pushButtonPin);

  pinMode(selector, INPUT);
  digitalRead(selector);

  pinMode(windshieldpower, OUTPUT);
  pinMode(frontlightspower, OUTPUT);
  pinMode(rearlightpower, OUTPUT);
  pinMode(radiopower , OUTPUT);
  pinMode(flashlightpower , OUTPUT);
  pinMode(hampower , OUTPUT);
  pinMode(antennaup, OUTPUT);
  pinMode(antennadown, OUTPUT);

  Serial.begin(9600);

}

void loop()
{
  currState = digitalRead(pushButtonPin);
  if (currState != prevState)
  {
    if (currState == HIGH)
    {
      pressCount++;

    }
    delay(10);
  }
  prevState = currState;

  currState2 = digitalRead(selector);
  if (currState2 != prevState2)
  {
    if (currState2 == HIGH)
    {
      selectCount++;
    }
    delay(100);
  }
  prevState2 = currState2;


  if(pressCount > 9)
  {
    pressCount = 0;
  }

  if(pressCount != lastpresscount)
  {

    if(pressCount == 1)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("windsheild");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = windshieldmode;

    }
    if(pressCount == 2)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("frontlights");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = frontlightsmode; 
    }
    if(pressCount == 3)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("rearlight");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = rearlightmode;   
    }
    if(pressCount == 4)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("radio");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = radiomode;   
    }
    if(pressCount == 5)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("flashlight");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = flashlightmode; 
    }
    if(pressCount == 6)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("HAM");
      lcd.setCursor(0,1);
      lcd.print("Mode:");
      selectCount = hammode; 
    }
    /* if(pressCount == 7){                  not using this yet
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Antenna"); 
     lcd.setCursor(0,1);
     lcd.print("Mode:");
     selectCount = antennamode;
     } */
    if(pressCount == 0)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Scout Control");

    }
  }

  Serial.println(selectCount);


  if(pressCount == 1)
  {
    if(selectCount == 0)
    {
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(windshieldpower,LOW); 
    }
    if(selectCount == 1)
    {
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(windshieldpower,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    windshieldmode = selectCount;
  }
  if(pressCount == 2)
  {
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(frontlightspower ,LOW); 
    }
    if(selectCount == 2)
    {
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(frontlightspower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    frontlightsmode = selectCount;
  }

  if(pressCount == 3)
  {
    if(selectCount == 0)
    {
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(rearlightpower ,LOW); 
    }
    if(selectCount == 2)
    {
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(rearlightpower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    rearlightmode = selectCount;
  }

  if(pressCount == 4)
  {
    if(selectCount == 0)
    {
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(radiopower ,LOW); 
    }
    if(selectCount == 2)
    {
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(radiopower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    radiomode = selectCount;
  }

  if(pressCount == 5)
  {
    if(selectCount == 0)
    {
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(flashlightpower ,LOW); 
    }
    if(selectCount == 2)
    {
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(flashlightpower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    flashlightmode = selectCount;
  }

  if(pressCount == 6)
  {
    if(selectCount == 0){
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(hampower ,LOW); 
    }
    if(selectCount == 2)
    {
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(hampower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    hammode = selectCount;
  }

  if(pressCount == 7)
  {
    if(selectCount == 0)
    {
      lcd.setCursor(7,1);
      lcd.print("OFF");
      digitalWrite(frontlightspower ,LOW); 
    }
    if(selectCount == 2)
    {
      lcd.setCursor(7,1);
      lcd.print(" ON");
      digitalWrite(frontlightspower ,HIGH);
    }
    if(selectCount > 1)
    {
      selectCount = 0;
    }

    frontlightsmode = selectCount;
  }


  lastpresscount = pressCount;

}



AWOL

Quote
Pin designators should be byte constants.

UKHeliBob

A couple of suggestions.

Instead of using a series of if tests to check the value of presscount use if/else.  This will avoid the program testing every value of pressount.  Alternatively change to using switch/case.  I find that easier to read than a series of ifs and it also avoids the program testing values that cannot be true.

Why do you have 2 sections of code testing the value of presscount ?  Could you not combine them ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up