compiling a led script delay control with button

Discussion in 'The Projects Forum' started by c32do, Aug 13, 2012.

  1. c32do

    Thread Starter New Member

    Aug 13, 2012
    3
    0
    Hello my friends
    This is what Ive got written and it seems okay to me but I think there are quite a few noob mistakes. Please help me edit so it is compiled correctly.

    Code ( (Unknown Language)):
    1. const int ledPin1 =  3;
    2. const int ledPin2 =  4;
    3. const int ledPin3 =  5;
    4. const int ledPin4 =  6;
    5. const int ledPin5 =  7;
    6. const int ledPin6 =  8;
    7. const int ledPin7=  9;
    8. const int ledPin8 =  10;
    9. const int ledPin9 =  11;
    10. const int ledPin10 =  12;
    11. const int ledPin11 =  13;
    12.  
    13. const int ledPin12 =  14;
    14. const int ledPin13 =  15;
    15. const int ledPin14 =  16;
    16.  
    17. const int ledPin15 =  17;
    18.  
    19.  
    20. const int buttonPin1 = 1;
    21. const int buttonPin2 = 2;
    22.  
    23.  
    24. int pinArray[] = {
    25.   3, 4, 5, 6, 7,8,9,10,11,12,13};
    26. int count = 0;
    27. int timer = 1000;
    28. int buttonPin1State = 0;
    29. int buttonPin2State = 0;
    30.  
    31.  
    32. void setup()
    33. {
    34.  
    35.  
    36.  
    37.  
    38.     pinMode(pinArray[count], OUTPUT);
    39.     pinMode(buttonPin2, INPUT);
    40.   }
    41.  
    42.  
    43.   void loop()
    44.   {
    45.     for (count=0;count<11;count++)
    46.     {
    47.       buttonPin1State = digitalRead(buttonPin1);
    48.       if (buttonPin1State == HIGH)
    49.         delay(timer*4);
    50.  
    51.       digitalWrite(pinArray[count], HIGH);
    52.       delay(timer);
    53.       digitalWrite(pinArray[count], LOW);
    54.       delay(timer*2);
    55.     }
    56.     for (count=0;count<11;count++)
    57.     {
    58.       digitalWrite(pinArray[count], HIGH);
    59.       delay(timer);
    60.       digitalWrite(pinArray[count], LOW);
    61.       delay(timer*2);
    62.     }
    63.     for (count=0;count<11;count++)
    64.     {
    65.       digitalWrite(pinArray[count], HIGH);
    66.       delay(timer);
    67.       digitalWrite(pinArray[count], LOW);
    68.       delay(timer*2);
    69. {
    70. {
    71.  
    72.  
    73.       digitalWrite(ledPin12, HIGH);
    74.       delay(2000);
    75.       digitalWrite(ledPin13, HIGH);
    76.       delay(2000);
    77.       digitalWrite(ledPin14, HIGH);
    78.       delay(2000);
    79.       digitalWrite(ledPin12, LOW);
    80.       digitalWrite(ledPin13, LOW);
    81.       digitalWrite(ledPin14, LOW);
    82.       delay(6000);
    83.  
    84.     }
    85.    
    86.  
    87.  
    88. {
    89. buttonPin2State = digitalRead(buttonPin2);
    90.  
    91.  
    92. if((buttonPin2State== HIGH) && (digitalRead(ledPin12) ==  HIGH))
    93.  
    94.                
    95.      }
    96.       for (count=0;count<11;count++ )
    97.       {
    98.         digitalWrite(pinArray[count], HIGH);
    99.         delay(timer);
    100.         digitalWrite(pinArray[count], LOW);
    101.         delay(timer);
    102. }
    103.      
    104.  
    105. else if ((buttonPin2State== HIGH) && (digitalRead(ledPin13) ==  HIGH))
    106.       }
    107.       for (count=0;count<11;count++)
    108.       {
    109.         digitalWrite(pinArray[count], HIGH);
    110.         delay(timer);
    111.         digitalWrite(pinArray[count], LOW);
    112.         delay(500);
    113.  
    114.       }
    115.     else((buttonPin2State== HIGH) && (digitalRead(ledPin14) ==  HIGH))
    116.     }
    117.  
    118.     for (count=0;count<11;count++)
    119.     {
    120.       digitalWrite(pinArray[count], HIGH);
    121.       delay(500);
    122.       digitalWrite(pinArray[count], LOW);
    123.       delay(0);
    124.  
    125.     }
    126. }
    127.  
    and how how can i do it so if led (12) high and button 2 is pressed(high) to change the delay time in the led pinarray. This seemed the most logical but I dont know if it will work Im sure there another way. This code setup is as follows:




    if((buttonPin2State== HIGH) && (digitalRead(ledPin12) == HIGH))


    }
    for (count=0;count<11;count++ )
    {
    digitalWrite(pinArray[count], HIGH);
    delay(timer);
    digitalWrite(pinArray[count], LOW);
    delay(timer);
    }


    else if ((buttonPin2State== HIGH) && (digitalRead(ledPin13) == HIGH))
     
Loading...