I am new to Ardiuno (actually new to programming too )
I created a Arduino Program which actually worked but the program look very lenthy and bit complicated to do a simple task (just to turn ON and OFF LEDs).
I want to use IF and FOR in my program which made my program bit complicated.
if someone can simpify it for me pls do
I already mention all details in program comments section
int ledSet1;
int ledSet2;
void setup()
{
 for (ledSet1 = 2; ledSet1 < 5; ledSet1++)
 {
  pinMode(ledSet1, OUTPUT);
 }
 for (ledSet2 = 5; ledSet2 < 8; ledSet2++)
 {
  pinMode(ledSet2,OUTPUT);
 }
}
void loop()
{
 int voltMetre = analogRead(A0);
 if (voltMetre < 511)
 {
  for (ledSet1 = 2; ledSet1 < 5; ledSet1++)
  {
   digitalWrite(ledSet1, HIGH);
  }
  for (ledSet2 = 5; ledSet2 < 8; ledSet2++)
  {
   digitalWrite(ledSet2, LOW);
  }
 }
 if (voltMetre > 511)
 {
  for (ledSet1 = 2; ledSet1 < 5; ledSet1++)
  {
   digitalWrite(ledSet1, LOW);
  }
  for (ledSet2 = 5; ledSet2 < 8; ledSet2++)
  {
   digitalWrite(ledSet2, HIGH);
  }
 }
}
Only add comments when they explain the why of the code.
"repeating" the code statements in text adds very little value.
using spaces between keywords and operators makes code much more readable
and they do not slow the code down runtime
From the cleanup I see that there is no action for the value 511 which is by design or ?