Larson Scanner using if(currentMillis - previousMillis > interval) {

While using the following code, the unit chases nicely. Trying now to get the Larson Scanner to work.

// constants won't change. Used here to
// set pin numbers:
const int ledPin[] = {3,4,5,6,7,8,9,10,11,12}; // the number of the LED pin

// Variables will change:
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 100;           // interval at which to blink (milliseconds)
int i = 0 ;
void setup() {
// set the digital pin as output:
for(int c = 0; c < 10; c++ ){
pinMode(ledPin[c], OUTPUT);
}  
}

void loop()
{

unsigned long currentMillis = millis();
                       digitalWrite(ledPin,HIGH);
                       
if(currentMillis - previousMillis > interval) {
  // save the last time you blinked the LED
  previousMillis = currentMillis;  

  // set the LED with the ledState of the variable:

  digitalWrite(ledPin, LOW);
 
if(i>=10){
i=-1;
}
i++;                      
}
//digitalWrite(ledPin, ledState);
}

To reverse the chase, you just make i = 10 and use i-- Getting the i to go from 0 to 9 and back is perplexing .

Any help on the Larson scanner would be appreciated. Thanks

harrybst:
While using the following code, the unit chases nicely. Trying now to get the Larson Scanner to work.

I very much doubt that. It doesn’t even compile!

Corrected version as a basis from which to work:

// constants won't change. Used here to set pin numbers:
const int ledPin[] = {
  3,4,5,6,7,8,9,10,11,12}; // the number of the LED pin

// Variables will change:
long previousMillis = 0;        // will store last time LED was updated

// the following variable is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 100;           // interval at which to blink (milliseconds)
int i = 0 ;
void setup() {
  // set the digital pin as output:
  for(int c = 0; c < 10; c++ ){
    pinMode(ledPin[c], OUTPUT);
  } 
}

void loop()
{
  unsigned long currentMillis = millis();
  digitalWrite(ledPin[i],HIGH);

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis; 

    // blank the current LED:
    digitalWrite(ledPin[i], LOW);

    if(i>=10){
      i=-1;
    }
    i++;                     
  }
}

Now there are (at least) a couple of ways to do the reversal.

So here is one:

// constants won't change. Used here to set pin numbers:
const int ledPin[] = {
  3,4,5,6,7,8,9,10,11,12}; // the number of the LED pin

// Variables will change:
long previousMillis = 0;        // will store last time LED was updated

// the following variable is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 100;           // interval at which to blink (milliseconds)

int toggle = 1;
int i = 0 ;                    // classic counter index :)

void setup() {
  // set the digital pin as output:
  for(int c = 0; c < 10; c++ ){
    pinMode(ledPin[c], OUTPUT);
  } 
}

void loop()
{
  unsigned long currentMillis = millis();
  digitalWrite(ledPin[i],HIGH);

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis; 

    // blank the current LED:
    digitalWrite(ledPin[i], LOW);

    i += toggle;
    if(i > 8 || i < 1){
      toggle = -toggle;
    }
  }
}

But this may interest you too:

// constants won't change. Used here to set pin numbers:
const int ledPin[] = {
  3,4,5,6,7,8,9,10,11,12}; // the number of the LED pin

// Variables will change:
long previousMillis = 0;        // will store last time LED was updated

// the following variable is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 100;           // interval at which to blink (milliseconds)

int toggle = 1;
int i = 0;                    // classic counter index :)
int ilast = 0;

void setup() {
  // set the digital pin as output:
  for(int c = 0; c < 10; c++ ){
    pinMode(ledPin[c], OUTPUT);
  } 
}

void loop()
{
  unsigned long currentMillis = millis();
  digitalWrite(ledPin[i],HIGH);

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis; 

    // blank the previous LED:
    digitalWrite(ledPin[ilast], LOW);

    ilast = i;
    i += toggle;
    if(i > 8 || i < 1){
      toggle = -toggle;
    }
  }
}

:grinning:

Paul__B: I very much doubt that. It doesn't even compile!

Minor detail.

Thank you ! I will give it a try.

IT WORKS ! Thank you ! May I send you a free board with some LEDs? If you would like specifications of the board, will be happy to send them to you . Now just need to add the DMX library and some code for the button switches. Much appreciated !

Paul__B: I very much doubt that. It doesn't even compile!

[quote author=Runaway Pancake date=1432387397 link=msg=2244537] Minor detail.

[/quote]

Good to see that you still have the dry sense of humour Dr Pancake :)

OP see this from Runaway Pancake

http://forum.arduino.cc/index.php?topic=171567.10