1

Given below is my loop and it counts 1 to 250 using the push button i just added this part as this one is the main part. I want to make it in steps like one press (push button) SETS IT TO 10 OR 20 ETC. Many thanks in advance for your kindness.

if ((digitalRead(2)==HIGH) && (digitalRead(7)==LOW))
 {
   if (j<255)
   {j++;
   lcd.setCursor(5,1);
   lcd.print("                ");
   lcd.setCursor(5,1);
   lcd.print(j);
   while((digitalRead(2)==HIGH) && (digitalRead(7)==LOW));}
 }
else if ((digitalRead(2)==LOW) && (digitalRead(7)==HIGH))
 {
   if (j>0)
   {j--;
   lcd.setCursor(5,1);
   lcd.print("                ");
   lcd.setCursor(5,1);
   lcd.print(j);
   while((digitalRead(2)==LOW) && (digitalRead(7)==HIGH));}
}

analogWrite(9,j);
//lcd.noDisplay();
lcd.display();
delay(100);

}
5
  • the title says i have a problem ... there is nothing said about a problem in your post ... what happens when you run the program? Commented Nov 19, 2021 at 3:41
  • Where is j defined? What do you see on the LCD? Commented Nov 19, 2021 at 6:15
  • If you want to change j in bigger steps, just replace j++ and j-- by for example j+=10 and j-=10. Though I suspect that thats not all of the problem Commented Nov 19, 2021 at 15:11
  • I actually added the part in which i was having trouble so the j was defined at the start of the code while i have posted the main part of the code (not the full code). I think comment from Chrisl has solved the problem i was facing, i'll try it later and update it here if its solved. Thanks a lot for your precious time. Commented Nov 19, 2021 at 20:10
  • Finally thanks Chrisl to understand my question and helping me out. It worked. Commented Nov 19, 2021 at 21:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.