code.docx

(12 KB) Pobierz

 

  int buttonPin = 5; //button plugged to digital pin 5

  int buttonVal = 0;

  int ledPin = 3; //led plugged to digital pin 3

 

  void setup(){

    pinMode(buttonPin, INPUT);

    pinMode(ledPin, OUTPUT);

  }

 

  void loop(){

    buttonVal=digitalRead(buttonPin);

    if(buttonVal==HIGH){

      blinkLED(5, 1000); //the arguments I put into the function determine number of blinks and delay

    }

  } //loop is closed here

 

  /*here is our custom function to blink LEDs.

  The arguments we defined are numBlinks for number of blinks, and del for the delay between blinks.

  We could put in any number of arguments to give the function more complex behaviors.

  */

  void blinkLED(int numBlinks, int del){

    for(int i=0; i<numBlinks; i++){

      digitalWrite(ledPin, HIGH);

      delay(del);

      digitalWrite(ledPin, LOW);

      delay(del);

    }

  }

   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  int buttonPin = 5; //button plugged to digital pin 5

  int buttonVal = 0;

  int ledPin = 3; //led plugged to digital pin 3

  int del = 1000; //length of delay in milliseconds

  int numberOfTimes = 5; //number of times the LED will blink.

 

  void setup(){

    pinMode(buttonPin, INPUT);

    pinMode(ledPin, OUTPUT);

  }

 

  void loop(){

    buttonVal=digitalRead(buttonPin);

    if(buttonVal==HIGH){

      for(int i=0; i<numberOfTimes; i++){ //using a global variable to set number of blinks.

      digitalWrite(ledPin, HIGH);

      delay(del);

      digitalWrite(ledPin, LOW);

      delay(del);

      }

    }

  }

   

 

 

 

 

 

 

 

 

 

 

  int buttonPin = 5; //button plugged to digital pin 5

  int buttonVal = 0;

  int ledPin = 3; //led plugged to digital pin 3

  int del = 1000; //length of delay in milliseconds

 

  void setup(){

    pinMode(buttonPin, INPUT);

    pinMode(ledPin, OUTPUT);

  }

 

  void loop(){

    buttonVal=digitalRead(buttonPin);

    if(buttonVal==HIGH){ //LED blinks twice when button is pressed

      digitalWrite(ledPin, HIGH);

      delay(del);

      digitalWrite(ledPin, LOW);

      delay(del);

      digitalWrite(ledPin, HIGH);

      delay(del);

      digitalWrite(ledPin, LOW);

      delay(del);

      }

   }

 

 

 

Zgłoś jeśli naruszono regulamin