Hello, im beginner programmer but i have to do , a little project.
This project have 6leds and 2 buttons..
First button make first sequence.
Second button make second sequence...
I write this code and he going to compile and flash to my arduino... But problem is when i try run (click any button) program... Doesnt work corectly.. I dont know what's happend with this.. somebody can looks at my code and tell me any suggestion and resolve problem with me?
This is code;
//Define all leds on which pins
#define leda 2
#define ledb 3
#define ledc 4
#define ledd 5
#define lede 6
#define ledf 7
#define buttona 12
#define buttonb 14
int ledPins = leda + ledb + ledc + ledd + lede + ledf;
int delayTime[] = {1000, 20000, 3000, 7000, 3000, 52000, 5000, 5000, 4000, 19000, 2000};
int pinCount = 6;
char seq1[] = {ledb, ledb, ledd, lede, lede, ledd, ledc, ledf, ledf ,ledc, leda};
char output1[] = {HIGH, LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, LOW, LOW, LOW};
int time1[] = {2000,20000,3000,7000,3000,52000,5000,5000,4000,19000,2000}; //11 +START
char seq2[] = {ledc, ledc, ledd, ledd, ledc, lede, lede, ledc, ledd, lede, lede, ledd, ledc, ledf, ledf, ledc, ledb};
char output2[] = {HIGH, LOW, HIGH, LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, LOW, LOW, LOW};
int time2[] = {1000,9000,2000,8000,3000,7000,2000,18000,2000,2000,2000,29000,5000,5000,2000,19000,2000}; //18 + START
int buttons = buttona + buttonb;
byte buttonState;
byte lastState = LOW;
byte count = 0;
int program_running = 0; // 0 - no program running, 1 - first program running (firts button pressed), 2 - ....
int start_milis = 0;
int seq_step = 0;
int interval = millis() - start_milis;
void setup() {
//Define all led and set all on OFF
pinMode(ledPins, OUTPUT);
//Safe implementation
pinMode(buttona,INPUT);
pinMode(buttonb,INPUT);
}
void loop() {
if( program_running == 1 ) {
int interval = millis() - start_milis;
sequence();
}
if( program_running == 2) {
int interval = millis() - start_milis;
sequence2();
}
//If pushbuttonA == sequence();
if(digitalRead(buttona) == LOW)
{
program_running = 1;
start_milis = millis();
count = 1;
sequence();
ButtonCounter();
}
//If pushbuttonB == sequence();
if(digitalRead(buttonb) == LOW)
{
program_running = 2;
start_milis = millis();
count = 1;
sequence2();
ButtonCounter();
}
}
void sequence(){
//First sequence:
digitalWrite(leda,HIGH);
if(interval > 2000)
{
interval = 0;
for(int forCount = 0; forCount < 12; forCount++)
{
if( interval > time1[seq_step])
{
digitalWrite(seq1[forCount],output1[forCount]);
seq_step++;
interval = 0;
}
};
}
//Complete sequence:
digitalWrite(ledPins,HIGH);
do
{
digitalWrite(ledPins,HIGH);
}while(ledPins == HIGH); loop();
//If push button twice time go to stoploop();
// if(pushbutton == down && sequence == run())
}
void sequence2(){
//Second sequence
digitalWrite(ledb,HIGH);
if(interval > 2000)
{
interval = 0;
for(int forCountB = 0; forCountB < 12; forCountB++)
{
if( interval > time1[seq_step])
{
digitalWrite(seq2[forCountB],output2[forCountB]);
seq_step++;
interval = 0;
}
};
}
//Complete sequence:
digitalWrite(ledPins,HIGH);
do
{
digitalWrite(ledPins,HIGH);
}while(ledPins == HIGH); loop();
//If push button twice time go to stoploop();
// if(pushbutton == down && sequence == run())
}
void stoploop(){
//Stop sequence
//Choose button and run sequence first or second
//If pushbuttonA == sequence();
if(digitalRead(buttona) == LOW)
{
count = 1;
sequence();
ButtonCounter();
}
//If pushbuttonB == sequence();
if(digitalRead(buttonb) == LOW)
{
count = 1;
sequence2();
ButtonCounter();
}
}
void ButtonCounter(){
buttonState = digitalRead(buttons);
if(buttonState == buttonState != lastState )
{
count++;
if(count >= 2)
do
{
//STOP sequence
loop();
} while(count >= 2);
}
}