Skip to main content
Formatted code
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 127

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);

}

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);

}

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);

}

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);

}
Source Link
Xaidi
  • 51
  • 4

i have problem in generating pwm in steps

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);

}