add value to a potentiometer

I am new to arduino, what the program has to do is turn on the led when the value is> = 25, I already have that, now what I try to do is that if I press the up switch it should increase to 26, and If I press the down switch, 1 must be subtracted leaving 25, and so on, UP = increases 1 value and Down = decreases 1, my problem is that the changes in the potentiometer are not reflected when I make the declaration, I am using proteus to simulate it.

int switchUp=1;
int switchUpDown=5;
int pot = A4; //pin for the potentiometer
int led = 0; // pin for the LED
int val = 0; // variable to store the value coming from the sensor
int up;
int down;

void setup() {
  pinMode(led, OUTPUT); 
  Serial.begin(9600);
  pinMode (switchUp,INPUT);
  pinMode (switchUpDown,INPUT);
}

void loop() {
    up=digitalRead(switchUp);
    down=digitalRead(switchUpDown);
    val = analogRead(pot); // read the value from the sensor

   if (up==HIGH)
   {
    val+10;
   }

  if (val>=250){
     digitalWrite(led, HIGH);  // turn the led on
  }
            
   else  {
 digitalWrite(led, LOW);   // turn the led off
  }      
 
}

helpp meee

@jav54

Have you by any chance got 2 accounts on this forum as the diagram seems very familiar, as does the subject of the query, and you are using the same IP address as another user

  if (up==HIGH)

Don't do something (increment/decrement) while the switch IS HIGH, do it when it BECOMES HIGH.

Look at the state change demo/example in the IDE

val+10; Does nothing at all.
Tryval += 10;

And if your diagram is correct then HIGH means that the switch is not pressed. And pin 0 is not a good one to connect the LED to. Avoid pins 0, 1 which are used by program load and Serial.

Steve

what I want to do is that when I press the UP switch I increase the percentage on the potentiometer

So, have you fixed the code?

jav54:
what I want to do is that when I press the UP switch I increase the percentage on the potentiometer

That's interesting but it's nothing like what the code seems to be trying to do.

It is obviously not possible to actually move a potentiometer by pressing buttons. The percentage you talk about isn't calculated or displayed anywhere so it's difficult to work out what it is that you actually want to do.

Steve

Perhaps zlroque, who has the same IP address, could help you

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.