plz correct this program...
it is for glowing led
int timer = 100; // The higher the number, the slower the timing.
int pins[] = {2,3,4,5,6,7}; // an array of pin numbers
int num_pins = 6; // the number of pins (i.e. the length of the array)
void setup()
{
int i;
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num pins - 1
pinMode(pins*, OUTPUT); // set each pin as an output*
}
void loop()
{
int i;
for (i = 0; i < num_pins; i++)
{ // loop through each pin...
digitalWrite(pins*, HIGH); // turning it on,*
delay(timer); // pausing,
digitalWrite(pins*, LOW); // and turning it off.*
}
for (i = num_pins - 1; i >= 0; i--)
{
digitalWrite(pins*, HIGH);*
delay(timer);
digitalWrite(pins*, LOW);*
}
}
There are many problems with your code. The code was not posted in code tags. The code is not formatted for readability, use autoformat (in Tools menu) or CTRL-T. There are missing curly brackets in the for loop in setup(). The pins array in all the for loops is missing an indexer. The code below is corrected for mentioned problems. It compiles but functionality is untested.
Please read the "how to use the forum" stickies to see how to properly format and post code.
int timer = 100; // The higher the number, the slower the timing.
const int pins[] = { // value will not change so const saves memory
2,3,4,5,6,7}; // an array of pin numbers
const int num_pins = 6; // the number of pins (i.e. the length of the array)
void setup()
{
int i;
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num pins - 1
{ // missing in OP
pinMode(pins[i], OUTPUT); // missing index // set each pin as an output
} // missing in OP
}
void loop()
{
int i;
for (i = 0; i < num_pins; i++)
{ // loop through each pin...
digitalWrite(pins[i], HIGH); // missing index // turning it on,
delay(timer); // pausing,
digitalWrite(pins[i], LOW); // missing index // and turning it off.
}
for (i = num_pins - 1; i >= 0; i--)
{
digitalWrite(pins[i], HIGH); // missing index
delay(timer);
digitalWrite(pins[i], LOW); // missing index
}
}
int timer = 100; // The higher the number, the slower the timing.
const int pins[] = { // value will not change so const saves memory
2,3,4,5,6,7}; // an array of pin numbers
const int num_pins = 6; // the number of pins (i.e. the length of the array)
Consider using byte as the data type to save memory unless timer ever goes above 255
Consider calculating num_pins to allow easy maintenance should the number of pins chanage
const byte num_pins = sizeof(pins) / sizeof(pins[0]);