The script has been compiled using Arduino Uno.
my old array was just using basic functions using delays etc. I am stuck with how to rewrite this snippet of code into my revised script. This bit of script wasn't even finished, but I got the basic idea of what I wanted to do. It played around with the delays to speed up a 5 led display blink array on the press of a button. So how do I change it to work in the revised script:
Revised script:
my old array was just using basic functions using delays etc. I am stuck with how to rewrite this snippet of code into my revised script. This bit of script wasn't even finished, but I got the basic idea of what I wanted to do. It played around with the delays to speed up a 5 led display blink array on the press of a button. So how do I change it to work in the revised script:
Rich (BB code):
buttonPin2State = digitalRead(buttonPin2);
if((buttonPin2State== HIGH) && (digitalRead(ledPin3) == HIGH)) {
for (count=0;count<5;count++ ) {
digitalWrite(pinArray[count], HIGH);
delay(timer*2);
digitalWrite(pinArray[count], LOW);
delay(timer);
}
}
else if ((buttonPin2State == HIGH) && (digitalRead(ledPin5) == HIGH)) {
for (count=0;count<5;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(500);
}
}
else if((buttonPin2State== HIGH) && (digitalRead(ledPin6) == HIGH)) {
for (count=0;count<5;count++) {
digitalWrite(pinArray[count], HIGH);
delay(400);
digitalWrite(pinArray[count], LOW);
delay(200);
}}}
Revised script:
Rich (BB code):
#include <TimerOne.h>
int ledArray1[]={3,5,6};
int ledArray2[]={9,10,11,7,12};
int countA=6,countB=10;
void setup()
{
int count=0;
while (count<3)
{
pinMode(ledArray1[count],OUTPUT);
pinMode(ledArray2[count],OUTPUT);
count++;
}
while (count<5)
{
pinMode(ledArray2[count],OUTPUT);
count++;
}
Timer1.initialize(1000000);
Timer1.attachInterrupt( loopLeds );
}
void loop()
void loopLeds()
{
if (countA<3) {
digitalWrite(ledArray1[countA],HIGH);
}
if (countA==3) {
digitalWrite(ledArray1[0],LOW);
digitalWrite(ledArray1[1],LOW);
digitalWrite(ledArray1[2],LOW);
}
countA++;
if (countA>=6) countA=0;
if (countB<5) {
digitalWrite(ledArray2[countB],LOW);
}
if (++countB>=10) countB=0;
if (countB<5) {
digitalWrite(ledArray2[countB],HIGH);
}
}