Hello
Im new to arduino and im learning from arduino for newbies. I have a question on the code on a lesson which is :
//Chapter 4: The All-Seeing Eye
//Sequentially lights up a series of LEDs
//A variable to set a delay time between each LED
int delayTime = 400;
//A variable to store which LED we are currently working on //it will also start with LED 4 (position 5)
int currentLED = 4;
//A variable to store the direction of travel
int dir = 1;
//A variable to store the last time we changed something
long timeChanged = 0;
//An array to hold the value for each LED pin
byte ledPin[] = {4,5,6,7,8,9,10,11,12,13};
void setup(){
// Set all pints for OUTPUT
for(int i=0;i<10;i++){
pinMode(ledPin[i], OUTPUT);
}
//Record the time once the setup has completed
timeChanged = millis();
}
void loop(){
//Check whether it has been long enough
if ((millis() - timeChanged) > delayTime){
//turn off all of the LEDs
for(int i =0; i< 10; i++){
digitalWrite(ledPin[i], LOW);
}
//Light the current LED
digitalWrite(ledPin[currentLED], HIGH);
//Increase the direction value (up or down)
currentLED = currentLED + dir;
//If we are at the end of a row, change direction
if (currentLED ==9){
dir = -1;
}
if (currentLED ==0){
dir = 1;
}
//store the current time as the time we last changed LEDs
timeChanged = millis();
}
}
On this line :
void loop(){
//Check whether it has been long enough
if ((millis() - timeChanged) > delayTime){
//turn off all of the LEDs
for(int i =0; i< 10; i++){
digitalWrite(ledPin[i], LOW);
}
//Light the current LED
digitalWrite(ledPin[currentLED], HIGH);
- Is it turning everything off first before putting one pin as HIGH? if Yes, I don't see all of the LEDs are turning off, instead, it run continuosly.
example :
First loop : Pin 3,5,6,7,8,9,10,11,12,13 are OFF
Pin 4 are ON
Second loop: Pin 3,4,6,7,8,9,10,11,12,13 are OFF
Pin 4 are ON
Third loop: Pin 3,4,5,7,8,9,10,11,12,13 are OFF
Pin 5 are ON
(and so on..)
From what I understand, it should Run like this:
First Loop: All Pins OFF
second Loop : Pin 3,5,6,7,8,9,10,11,12,13
Pin 4 are ON
third loop : All Pins OFF
Fourth loop : Pin 3,4,6,7,8,9,10,11,12,13
Pin 5 are ON
(and so on)
- If both code run at the same time,isn't it creates conflict? where it ask to turn ALL Low and HIGH on a certain PIN at the same time. Isn't the code at the 'certain' PIN conflicts?
Thanks