fadeenk

Project 1

Sep 8th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. //this file goes into the arduino software
  2.  
  3. const int buttonPin = 2;     // the number of the pushbutton pin
  4. const int ledPin1 =  13;      // the number of the LED pin
  5. const int ledPin2 =  12;
  6. const int ledPin3 =  8;
  7. const int ledPin4 =  7;
  8. const int ledPin5 =  4;
  9.  
  10. // variables will change:
  11. int buttonState = 0;         // variable for reading the pushbutton status
  12.  
  13. void setup() {
  14.   // initialize the LED pin as an output:
  15.   pinMode(ledPin1, OUTPUT);
  16.   pinMode(ledPin2, OUTPUT);        
  17.   pinMode(ledPin3, OUTPUT);
  18.   pinMode(ledPin4, OUTPUT);        
  19.   pinMode(ledPin5, OUTPUT);  
  20.   // initialize the pushbutton pin as an input:
  21.   pinMode(buttonPin, INPUT);    
  22. }
  23.  
  24. void loop(){
  25.   // read the state of the pushbutton value:
  26.   buttonState = digitalRead(buttonPin);
  27.   int x = 100; // delay varaible
  28.   int pin = 0; // intiate pin value that will be used in the loop
  29.  
  30.   // check if the pushbutton is pressed.
  31.   // if it is, the buttonState is HIGH:
  32.   if (buttonState == HIGH) {    
  33.     // turn LED on:
  34.     for(int i = 0; i <20; i++){ //for loop for all of leds
  35.      for(int i=1; i<=5; i++){ //for loop that turns on and off each led
  36.        if(i==5){
  37.          pin=4;
  38.        }
  39.        if(i==4){
  40.          pin=7;
  41.        }
  42.        if(i==3){
  43.          pin=8;
  44.        }
  45.        if(i==2){
  46.          pin=12;
  47.        }
  48.        if(i==1){
  49.          pin=13;
  50.        }
  51.         digitalWrite(pin, HIGH);
  52.         delay(x);
  53.         digitalWrite(pin, LOW);
  54.      }
  55.     }
  56.   }
  57.   else {
  58.     // turn LED off:
  59.     digitalWrite(ledPin1, LOW);
  60.     digitalWrite(ledPin2, LOW);
  61.     digitalWrite(ledPin3, LOW);
  62.     digitalWrite(ledPin4, LOW);
  63.     digitalWrite(ledPin5, LOW);
  64.   }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment