okay so im struggling with something.
I'm trying to make a larson scanner with the arduino, the problem is i CANNOT use the delay function. I can make the scanner with it, but it locks out the cpu and i need some other functions running which wont work because of the delay.
so using this example
and the code i already have which is minimal:
I simply cannot work out how to get the scanner to do what i want it to. which this:
led 1 comes on > led 2 comes on> led 1 turns off and led 3 turns on > led 2 turns of and led 4 turns on
with a time of 50ms between the functions (but led 1 turning off at same time as led 3 turning on)
can someone help me out by getting the first 3 led's working? after that i can type up the rest of the code as it turns out i can understand the code if i can type it out copying something that already works. bazaare i know but hey we all learn in different ways.
I'm trying to keep each led's function seperated out so that i can add in other code along the way and get other functions running in the right places.
I'm trying to make a larson scanner with the arduino, the problem is i CANNOT use the delay function. I can make the scanner with it, but it locks out the cpu and i need some other functions running which wont work because of the delay.
so using this example
Rich (BB code):
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
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 = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
Rich (BB code):
int pinled1 = 13;
int pinled2 = 12;
int pinled3 = 11;
int pinled4 = 10;
int pinled5 = 9;
int pinled6 = 8;
int pinled7 = 7;
void setup() {
pinMode(pinled1, OUTPUT);
pinMode(pinled2, OUTPUT);
pinMode(pinled3, OUTPUT);
pinMode(pinled4, OUTPUT);
pinMode(pinled5, OUTPUT);
pinMode(pinled6, OUTPUT);
}
void loop()
{
}
led 1 comes on > led 2 comes on> led 1 turns off and led 3 turns on > led 2 turns of and led 4 turns on
with a time of 50ms between the functions (but led 1 turning off at same time as led 3 turning on)
can someone help me out by getting the first 3 led's working? after that i can type up the rest of the code as it turns out i can understand the code if i can type it out copying something that already works. bazaare i know but hey we all learn in different ways.
I'm trying to keep each led's function seperated out so that i can add in other code along the way and get other functions running in the right places.