In the previous section I talked about how to make a LED Night Rider pattern using the inputs ...
But you may have noticed that one code is too long. So we can't write this code in fewer lines ??? Yes, we can write this code in fewer lines. This is the code that ...
int pinArray [] = {2, 3, 4, 5, 6,};
int count = 0;
void setup () {
for (count = 0; count <6; count ++) {
pinMode (pinArray [count], OUTPUT);
}
}
void loop () {
for (count = 0; count <5; count ++) {
digitalWrite (pinArray [count], HIGH);
delay (100);
digitalWrite (pinArray [count], LOW);
delay (100);
}
for (count = 4; count> = 0; count--) {
digitalWrite (pinArray [count], HIGH);
delay (100);
digitalWrite (pinArray [count], LOW);
delay (100);
}
}
You now realize that the code is shorter than the original code ...
);
So let's see what this code says ...
I've mentioned a lot of what the code says in the previous section ...
The first thing you'll notice is int pinArray [] = {2,3,4,5,6}; You already know what this int means ... an int array has been introduced called pinArray after the int. An Array is a string of values that we need to assign to the same variable ... So the data type in this Array is int. [] This is where this code is called an array. So all the data in this array has to be inserted into the {5 ... brackets ... In this code, 2,3,4,5,6 pin 5 is entered into the array.
So using another for loop, the code in the previous section can be written in as few lines as this ...
0 Comments