While Loop

I have some code to run inside set up so I can adjust the value with button’s, It comes up initialising on my LCD, The manual button works and it continues to the void loop() part and my program runs,
The trouble is that the target_ma variable does not respond to my button press’s, I know the buttons work because I’ve changed the pins around. I may have it set up wrong but looks ok to me

void setup() {

  lcd.createChar(1, bell);                       // Bell char for LCD. Displayed when sounder is enabled.
  pinMode(manual_pin, INPUT);                    // MAN/RUN switch. Grounded in MAN position.
  digitalWrite(manual_pin, HIGH);
  pinMode(upbutton, INPUT);                    // up switch. Grounded in MAN position.
  digitalWrite(upbutton, HIGH);                // Enable internal pullup resistor.
  pinMode(downbutton, INPUT);                  // Down switch. Grounded in MAN position.
  digitalWrite(downbutton, HIGH);              // Enable internal pullup resistor.
  pinMode(end_pin, OUTPUT);                      // Output to LD to signal end of test.
  digitalWrite(end_pin, LOW);

  pinMode(end_sounder, OUTPUT);                  // Output to sounder.
  digitalWrite(end_sounder, LOW);

  pinMode(pwm_pin, OUTPUT);                      // Set up 10-bit DAC pin as output
  Timer1.initialize(period);                     //
  Timer1.pwm(pwm_pin, pwm);                      // and set zero PWM out

  ina219.begin();                                // Initialise INA219 Current Sensor

  Serial.begin(9600);                           // Initialise Arduino to PC Com Port

  lcd.begin(20, 4);                              // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print("Initialising...");                  // Print something on the display to show
  delay(1000);                                   // it's working.

  lcd.clear();                                   // Clear display
  delay(100);

  while (digitalRead(manual_pin) == HIGH) {          // Loop here to adjust desired load mA manually
    lcd.setCursor(0, 1);
    lcd.print("Set mA: ");
    manual = true;

    // target_mA = map(analogRead(manual_value), 0, 1023, 0, 1500);
    if (upbutton == LOW) {           //If up button is pressed increase value
      target_mA = target_mA ++;
      if (target_mA > 1500) {
        target_mA = 1500;
      }
    }
    if (downbutton == LOW) {
      target_mA = target_mA --;     //If down button is pressed increase value
      if (target_mA < 0) {
        target_mA = 0;
      }
    }
    lcd.setCursor(10, 1);
    lcd.print("      ");
    lcd.setCursor(10, 1);
    lcd.print(target_mA);
    time_limit = 480;                               // 8 hours. Test relies on the..
    cutoff_voltage = 3.0;                           // 3.0 volts cutoff voltage.
    kP = 30;                                        // Default values are used in Manual Mode.
    offset = 0;
    tolerance = 1;
    beep = 1;
    delay(100);
  }

 
  /* These lines echo the received values to the LCD and display for 5 seconds  */

  lcd.clear();
  delay(100);
  lcd.print("Target mA   "); lcd.print(target_mA);
  lcd.setCursor(0, 1);
  lcd.print("Cutoff v    "); lcd.print(cutoff_voltage);
  if (beep == 1) {
    lcd.setCursor(19, 0);
    lcd.write(1);
  }
  lcd.setCursor(0, 2);
  lcd.print("Time (min)  "); lcd.print(time_limit);
  lcd.setCursor(0, 3); lcd.print("S="); lcd.print(sampleTime / 1000);
  lcd.print(" t="); lcd.print(tolerance); lcd.print(" kP="); lcd.print((int)kP);
  lcd.print(" i="); lcd.print(offset, 1);


  delay(5000);
  lcd.clear();
  startMillisec = millis();                        // get millisec time at start
  if (beep == 1) {
    digitalWrite(end_sounder, HIGH);               // Bleep once to indicate test starting.
    delay(50);
    digitalWrite(end_sounder, LOW);
  }
}

This part adjusts the target_ma, but I don’t want to use a pot I need buttons to adjust the value, Line below works
target_mA = map(analogRead(manual_value), 0, 1023, 0, 1500);

target_mA = target_mA ++;

oopsies.

This can be

target_mA++;

or

target_mA = target_mA +1;

Mixing them like that is undefined.

Delta_G:

target_mA = target_mA ++;

oopsies.

This can be

target_mA++;

or

target_mA = target_mA +1;

Mixing them like that is undefined.

I've tried both ways and still the same the value does not increase/decrease

Post your newly modified code

Oh, sorry I missed this one.

if (upbutton == LOW) {

Will upbotton (the pin number) ever equal LOW? Since you haven't posted the complete code I don't know what upbutton is defined as, but I doubt it is pin 0.

Perhaps you meant to do a digitalRead here?

This is what my pin numbers are set up has

int manual_pin = 12;                         // Manual/Run switch. Grounded in Manual.
int manual_value = A3;                       // Set target discharge current with potentiometer
int upbutton  = 11;
int downbutton = 10;

and I’ve tried this

int manual_pin = 11;                         // Manual/Run switch. Grounded in Manual.
int manual_value = A3;                       // Set target discharge current with potentiometer
int upbutton  = 12;
int downbutton = 10;

here is the new modified code

void setup() {

  lcd.createChar(1, bell);                       // Bell char for LCD. Displayed when sounder is enabled.
  pinMode(manual_pin, INPUT);                    // MAN/RUN switch. Grounded in MAN position.
  digitalWrite(manual_pin, HIGH);
  pinMode(upbutton, INPUT);                    // up switch. Grounded in MAN position.
  digitalWrite(upbutton, HIGH);                // Enable internal pullup resistor.
  pinMode(downbutton, INPUT);                  // Down switch. Grounded in MAN position.
  digitalWrite(downbutton, HIGH);              // Enable internal pullup resistor.
  pinMode(end_pin, OUTPUT);                      // Output to LD to signal end of test.
  digitalWrite(end_pin, LOW);

  pinMode(end_sounder, OUTPUT);                  // Output to sounder.
  digitalWrite(end_sounder, LOW);

  pinMode(pwm_pin, OUTPUT);                      // Set up 10-bit DAC pin as output
  Timer1.initialize(period);                     //
  Timer1.pwm(pwm_pin, pwm);                      // and set zero PWM out

  ina219.begin();                                // Initialise INA219 Current Sensor

  Serial.begin(9600);                           // Initialise Arduino to PC Com Port

  lcd.begin(20, 4);                              // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print("Initialising...");                  // Print something on the display to show
  delay(1000);                                   // it's working.

  lcd.clear();                                   // Clear display
  delay(100);

  while (digitalRead(manual_pin) == HIGH) {          // Loop here to adjust desired load mA manually
    lcd.setCursor(0, 1);
    lcd.print("Set mA: ");
    manual = true;

  // target_mA = map(analogRead(manual_value), 0, 1023, 0, 1500);
    if (upbutton == LOW) {           //If up button is pressed increase value
      target_mA++;
      if (target_mA > 1500) {
        target_mA = 1500;
      }
    }
    if (downbutton == LOW) {
      target_mA--;     //If down button is pressed increase value
      if (target_mA < 0) {
        target_mA = 0;
      }
    }
   
   // lcd.setCursor(10, 1);
    //lcd.print("  ");
    lcd.setCursor(7, 1);
    lcd.print(target_mA);
    time_limit = 2;                               // 8 hours. Test relies on the..
    cutoff_voltage = 3.0;                           // 3.0 volts cutoff voltage.
    kP = 30;                                        // Default values are used in Manual Mode.
    offset = 0;
    tolerance = 1;
    beep = 1;
    delay(100);
  }

 
  /* These lines echo the received values to the LCD and display for 5 seconds  */

  lcd.clear();
  delay(100);
  lcd.print("Target mA   "); lcd.print(target_mA);
  lcd.setCursor(0, 1);
  lcd.print("Cutoff v    "); lcd.print(cutoff_voltage);
  if (beep == 1) {
    lcd.setCursor(19, 0);
    lcd.write(1);
  }
  lcd.setCursor(0, 2);
  lcd.print("Time (min)  "); lcd.print(time_limit);
  lcd.setCursor(0, 3); lcd.print("S="); lcd.print(sampleTime / 1000);
  lcd.print(" t="); lcd.print(tolerance); lcd.print(" kP="); lcd.print((int)kP);
  lcd.print(" i="); lcd.print(offset, 1);


  delay(5000);
  lcd.clear();
  startMillisec = millis();                        // get millisec time at start
  if (beep == 1) {
    digitalWrite(end_sounder, HIGH);               // Bleep once to indicate test starting.
    delay(50);
    digitalWrite(end_sounder, LOW);
  }
}

and also tried this way

void setup() {

  lcd.createChar(1, bell);                       // Bell char for LCD. Displayed when sounder is enabled.
  pinMode(manual_pin, INPUT);                    // MAN/RUN switch. Grounded in MAN position.
  digitalWrite(manual_pin, HIGH);
  pinMode(upbutton, INPUT);                    // up switch. Grounded in MAN position.
  digitalWrite(upbutton, HIGH);                // Enable internal pullup resistor.
  pinMode(downbutton, INPUT);                  // Down switch. Grounded in MAN position.
  digitalWrite(downbutton, HIGH);              // Enable internal pullup resistor.
  pinMode(end_pin, OUTPUT);                      // Output to LD to signal end of test.
  digitalWrite(end_pin, LOW);

  pinMode(end_sounder, OUTPUT);                  // Output to sounder.
  digitalWrite(end_sounder, LOW);

  pinMode(pwm_pin, OUTPUT);                      // Set up 10-bit DAC pin as output
  Timer1.initialize(period);                     //
  Timer1.pwm(pwm_pin, pwm);                      // and set zero PWM out

  ina219.begin();                                // Initialise INA219 Current Sensor

  Serial.begin(9600);                           // Initialise Arduino to PC Com Port

  lcd.begin(20, 4);                              // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print("Initialising...");                  // Print something on the display to show
  delay(1000);                                   // it's working.

  lcd.clear();                                   // Clear display
  delay(100);

  while (digitalRead(manual_pin) == HIGH) {          // Loop here to adjust desired load mA manually
    lcd.setCursor(0, 1);
    lcd.print("Set mA: ");
    manual = true;

  // target_mA = map(analogRead(manual_value), 0, 1023, 0, 1500);
    if (digitalRead(upbutton == LOW)) {           //If up button is pressed increase value
      target_mA++;
      if (target_mA > 1500) {
        target_mA = 1500;
      }
    }
    if (digitalRead(downbutton == LOW)) {
      target_mA--;     //If down button is pressed increase value
      if (target_mA < 0) {
        target_mA = 0;
      }
    }
   
   // lcd.setCursor(10, 1);
    //lcd.print("  ");
    lcd.setCursor(7, 1);
    lcd.print(target_mA);
    time_limit = 2;                               // 8 hours. Test relies on the..
    cutoff_voltage = 3.0;                           // 3.0 volts cutoff voltage.
    kP = 30;                                        // Default values are used in Manual Mode.
    offset = 0;
    tolerance = 1;
    beep = 1;
    delay(100);
  }

 
  /* These lines echo the received values to the LCD and display for 5 seconds  */

  lcd.clear();
  delay(100);
  lcd.print("Target mA   "); lcd.print(target_mA);
  lcd.setCursor(0, 1);
  lcd.print("Cutoff v    "); lcd.print(cutoff_voltage);
  if (beep == 1) {
    lcd.setCursor(19, 0);
    lcd.write(1);
  }
  lcd.setCursor(0, 2);
  lcd.print("Time (min)  "); lcd.print(time_limit);
  lcd.setCursor(0, 3); lcd.print("S="); lcd.print(sampleTime / 1000);
  lcd.print(" t="); lcd.print(tolerance); lcd.print(" kP="); lcd.print((int)kP);
  lcd.print(" i="); lcd.print(offset, 1);


  delay(5000);
  lcd.clear();
  startMillisec = millis();                        // get millisec time at start
  if (beep == 1) {
    digitalWrite(end_sounder, HIGH);               // Bleep once to indicate test starting.
    delay(50);
    digitalWrite(end_sounder, LOW);
  }
}
 if (digitalRead(upbutton == LOW))

You're getting closer. Let's evaluate this expression.

Inside most parenthesis first. (upbotton == LOW). Nope, upbutton does not equal 0, so this is false. False is zero. So now we have this.

 if (digitalRead(0))

That's not right is it?

Watch where you put your parenthesis.

 if (digitalRead(upbutton) == LOW)

I know the buttons work because I've changed the pins around. I may have it set up wrong but looks ok to me

Well that is a great way of knowing if something works.

Other mere mortals have to resort to actually testing buttons with a simple sketch to do something like turn on and off the pin 13 LED. But hey why should you bother with all that when it looks OK to you? I hope to be that good one day.

Here is a tip. When you post all your code POST ALL YOUR CODE!
Do this and it can be compiled and checked by others.

Now spot what you did? posting it in little bits so we have to stitch something together which may or may not be your code.

Grumpy_Mike:
Well that is a great way of knowing if something works.

Other mere mortals have to resort to actually testing buttons with a simple sketch to do something like turn on and off the pin 13 LED. But hey why should you bother with all that when it looks OK to you? I hope to be that good one day.

I can see why they call you Grumpy_mike, I know the buttons work if you bothered to read my post correctly you would have read BECAUSE I CHANGED THE BUTTONS ROUND ON THE PORTS SO UPBUTTON BECOMES MANUAL_PIN AND WHEN I PRESS THAT IT CONTUINES SO DID IT WHEN I CAHNGED THE OTHERS AROUND BUT STILL THE SAME.

Also if you look at my post count I’m new and still learning and I wished I was good as you with your post count :), Rant over but comments like yours DONNOT help or boost my confidence, It’s like learning to drive a car where all other (good drivers like yourself)drivers ranted at learner drivers for been slow, which we all was leaner drivers at some point , but like yourself and myself we forget that because we had years experience in hand so lots like learning to program

But I will try a little simple like turning a LED on/off with them as it’s all part of the learning curve, Yes you are correct it’s not all my code but bits of other peoples code which is why I’m trying to amend it and get it working the way I need to all part of the learning, I think you learn lots more by reading other peoples code and find better ways of doing it

Here is the FULL version of latest code, LOOP just consists of a counter with 1 second delay after I removed all other code as I'm trying get the first part working then add the rest of my own code step by step rather than running before walking :) 
[code#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
         // Output pin for end of test LED
int manual_pin = 12;                         // Manual/Run switch. Grounded in Manual.
int upbuttonpin = 11;// Set target discharge current with potentiometer
int upbutton;
int downbutton = 10;
int count_timer;
int target_mA;
boolean manual = false;


void setup() {

 
  pinMode(manual_pin, INPUT);                    // MAN/RUN switch. Grounded in MAN position.
  digitalWrite(manual_pin, HIGH);
  pinMode( upbuttonpin, INPUT);                    // up switch. Grounded in MAN position.
  digitalWrite( upbuttonpin, HIGH);                // Enable internal pullup resistor.
  pinMode(downbutton, INPUT);                  // Down switch. Grounded in MAN position.
  digitalWrite(downbutton, HIGH);              // Enable internal pullup resistor.
 
  Serial.begin(9600);                           // Initialise Arduino to PC Com Port

  lcd.begin(20, 4);                              // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print("Initialising...");                  // Print something on the display to show
  delay(1000);                                   // it's working.

  lcd.clear();                                   // Clear display
  delay(100);

  while (digitalRead(manual_pin) == HIGH) {          // Loop here to adjust desired load mA manually
    lcd.setCursor(0, 1);
    lcd.print("Set mA: ");
    manual = true;
 upbutton = digitalRead(upbuttonpin);
  // target_mA = map(analogRead(manual_value), 0, 1023, 0, 1500);
   if (digitalRead(upbuttonpin) ==LOW);{
         target_mA++;
      if (target_mA > 1500) {
        target_mA = 1500;
      }
    }
    if (digitalRead(downbutton) == LOW) {
      target_mA--;     //If down button is pressed increase value
      if (target_mA < 0) {
        target_mA = 0;
      }
    }
   
    lcd.setCursor(10, 1);
   lcd.print("  ");
    lcd.setCursor(7, 1);
    lcd.print(target_mA);
    delay(100);
  }
lcd.setCursor(0, 1);
    lcd.print("Target mA   "); lcd.print(target_mA);
  lcd.setCursor(0, 2);
  lcd.print("NOW MOVING TO COUNTER");
  //lcd.write(1);
  lcd.clear();
   delay(5000);
  }




void loop() {
 count_timer ++;
 delay(1000);
 
  lcd.setCursor(0, 1);
  lcd.print("counter"); lcd.print(count_timer);
  }

it just counts up now it will stop counting up if I holed the button down the same even if I change LOW to HIGH, Delta_G thanks for taking the time to help I’m making little progress

@Steveiboy: You need to cut Grumpy_mike some slack. With over 41,000 posts and 1000 Karma points, he's probably read half a million posts and a good percentage of them repeat the same type of mistakes over and over. I get grumpy when I see people post source code without using code tags, despite the efforts of Nick Gammon and his posts at the top of this Forum. Rather the poking Mike with a pointy stick, shi*-can the hubris, and realize he has something to teach you. Learning how to code here will result in some knots on your head and dents to your ego. You may as well accept those as part of the process.

if (digitalRead(upbuttonpin) == LOW);

You seem to have picked up something extra there. I'm surprised that it doesn't just count up uncontrollably really really fast.

This is now counting up when I press the button down and stops when I release it, but the count down is not counting down when I press the button, Delta_g I just added upbuttonpin and removed upbutton as I started again in new window as I was getting lost in my mistakes

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
         // Output pin for end of test LED
int manual_pin = 12;                         // Manual/Run switch. Grounded in Manual.
int upbuttonpin = 11;// Set target discharge current with potentiometer
int upbutton;
int downbutton = 10;
int count_timer;
int target_mA;
boolean manual = false;

//
void setup() {

 
  pinMode(manual_pin, INPUT);                    // MAN/RUN switch. Grounded in MAN position.
  digitalWrite(manual_pin, HIGH);
  pinMode( upbuttonpin, INPUT);                    // up switch. Grounded in MAN position.
  digitalWrite( upbuttonpin, HIGH);                // Enable internal pullup resistor.
  pinMode(downbutton, INPUT);                  // Down switch. Grounded in MAN position.
  digitalWrite(downbutton, HIGH);              // Enable internal pullup resistor.
 
  Serial.begin(9600);                           // Initialise Arduino to PC Com Port

  lcd.begin(20, 4);                              // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print("Initialising...");                  // Print something on the display to show
  delay(1000);                                   // it's working.

  lcd.clear();                                   // Clear display
  delay(100);

  while (digitalRead(manual_pin) == HIGH) {          // Loop here to adjust desired load mA manually
    lcd.setCursor(0, 1);
    lcd.print("Set mA: ");
    manual = true;
 //upbutton = digitalRead(upbuttonpin);
  // target_mA = map(analogRead(manual_value), 0, 1023, 0, 1500);
   if (digitalRead(upbuttonpin) ==HIGH);{
         target_mA++;
      if (target_mA > 1500) {
        target_mA = 1500;
      }
    }
    if (digitalRead(downbutton) == HIGH) {
      target_mA--;     //If down button is pressed increase value
      if (target_mA < 0) {
        target_mA = 0;
      }
    }
   
    lcd.setCursor(10, 1);
   lcd.print("  ");
    lcd.setCursor(7, 1);
    lcd.print(target_mA);
    delay(100);
  }
lcd.setCursor(0, 1);
    lcd.print("Target mA   "); lcd.print(target_mA);
  lcd.setCursor(0, 2);
  lcd.print("NOW MOVING TO COUNTER");
  //lcd.write(1);
  lcd.clear();
   delay(5000);
  }




void loop() {
 count_timer ++;
 delay(1000);
 
  lcd.setCursor(0, 1);
  lcd.print("counter"); lcd.print(count_timer);
  }

econjack Yes I know he is a clever guy and knows his stuff may be I should have not typed that stuff and by saying it your more than likely to get less help , But when you have learning difficulty’s like myself you sometimes struggle to get it across what your trying to say or explain what the problem is, my bad sorry, plus as you can see I’m having a good go at it trying to solve it, may be some people are to quick to judge

if (digitalRead(upbuttonpin) ==HIGH);{

Still have that mistake.

Is it not counting down, or is something in that line I just quoted causing it to also unconditionally count up as well each time cancelling out your down count.

IF I have this

if (digitalRead(upbuttonpin) ==LOW);{

it just counts up on it's own without pressing the button and if I press the upbutton it stops counting until I release the button but with this bit of code it adds the counts up to 1500 if I held the button down and stops when I release the button which is what I wanted

if (digitalRead(upbuttonpin) ==HIGH);{

But when I press the down button on it's own it does not count down back to zero
tried this for button down

if (digitalRead(downbutton) ==LOW);{

and this way but still the same it does not count down

if (digitalRead(downbutton) ==HIGH);{

A semicolon on the end of an if statement ends the statement block. It essentially means, if this then do nothing. The next line or block of code will be run unconditionally.

I was hoping you'd see that one since you seemed to have known to leave them off in the code before.

Thanks Delta_g I now have it working simple when I look back but I guess its like the saying you can’t see the wood through the tress when it’s staring you in the face :slight_smile:

Here is the working code, please say if it can be improved or better way of doing it

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
         // Output pin for end of test LED
int manual_pin = 12;                         // Manual/Run switch. Grounded in Manual.
int upbuttonpin = 11;// Set target discharge current with potentiometer
int upbutton;
int downbutton = 10;
int count_timer;
int target_mA;
boolean manual = false;

//
void setup() {

 
  pinMode(manual_pin, INPUT);                    // MAN/RUN switch. Grounded in MAN position.
  digitalWrite(manual_pin, HIGH);
  pinMode( upbuttonpin, INPUT);                    // up switch. Grounded in MAN position.
  digitalWrite( upbuttonpin, HIGH);                // Enable internal pullup resistor.
  pinMode(downbutton, INPUT);                  // Down switch. Grounded in MAN position.
  digitalWrite(downbutton, HIGH);              // Enable internal pullup resistor.
 
  Serial.begin(9600);                           // Initialise Arduino to PC Com Port

  lcd.begin(20, 4);                              // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print("Initialising...");                  // Print something on the display to show
  delay(1000);                                   // it's working.

  lcd.clear();                                   // Clear display
  delay(100);

  while (digitalRead(manual_pin) == HIGH) {          // Loop here to adjust desired load mA manually
    lcd.setCursor(0, 1);
    lcd.print("Set mA: ");
    manual = true;
 //upbutton = digitalRead(upbuttonpin);
  // target_mA = map(analogRead(manual_value), 0, 1023, 0, 1500);
   if (digitalRead(upbuttonpin) ==HIGH){
         target_mA++;
      if (target_mA > 1500)
        target_mA = 1500;
      }
   
   if (digitalRead(downbutton) == HIGH) {
      target_mA--;     //If down button is pressed increase value
      if (target_mA < 0) 
        target_mA = 0;
      
    }
      
    lcd.setCursor(10, 1);
   lcd.print("  ");
    lcd.setCursor(7, 1);
    lcd.print(target_mA);
    delay(100);
  }
lcd.setCursor(0, 1);
    lcd.print("Target mA   "); lcd.print(target_mA);
  lcd.setCursor(0, 2);
  lcd.print("NOW MOVING TO COUNTER");
  //lcd.write(1);
  lcd.clear();
   delay(5000);
  }




void loop() {
 count_timer ++;
 delay(1000);
 
  lcd.setCursor(0, 1);
  lcd.print("counter"); lcd.print(count_timer);
  }
 if (digitalRead(upbuttonpin) ==HIGH){
         target_mA++;
      if (target_mA > 1500)
        target_mA = 1500;
      }

I noticed you have internal pullups turned on in setup. So doesn't this actually read, increment the target_mA whenever the button ISN'T pressed?

Well it worked ok as it was then when you pointed that out I looked a little closer then I changed it to low it counted the opposite way but managed to understand and sort that out this code is now working well so hopefully now I got it correct

while (digitalRead(manual_pin) == HIGH) {          // Loop here to adjust desired load mA manually
    lcd.setCursor(0, 1);
    lcd.print("Set mA: ");
    manual = true;
    if (digitalRead(upbuttonpin) ==LOW){
         target_mA--;
      if (target_mA <0)
        target_mA = 0;
      }
   
   if (digitalRead(downbutton) == LOW) {
      target_mA++;     //If down button is pressed increase value
      if (target_mA >100) //changed to 100 got fed up of counting to 1500 :-))
        target_mA = 100;  //changed to 100 got fed up of counting to 1500 :-))
      
    }
      
  // lcd.setCursor(10, 1);
    //lcd.print("  ");
    lcd.setCursor(7, 1);
    lcd.print(target_mA);
    lcd.print("  ");
    time_limit = 2;                               // 8 hours. Test relies on the..
    cutoff_voltage = 3.0;                           // 3.0 volts cutoff voltage.
    kP = 30;                                        // Default values are used in Manual Mode.
    offset = 0;
    tolerance = 1;
    beep = 1;
    delay(100);
  }