dilluns, 13 de novembre del 2017

Bloc2. Conceptes. Entrades digitals

Exemple 2.7

/*
* _2.7_digital_input
* 
* The board will turn the on-board LED on or off
*
* (c) 2013-2016 Arduino LLC.
*/

int inputPin = 5;
int ledPin = 13;

void setup() {
  pinMode(inputPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (digitalRead(inputPin) == HIGH) {
    digitalWrite(ledPin, HIGH);
  } 
  else {
    digitalWrite(ledPin, LOW);
  }
}


Exemple 2.8

/*
* _2.8_digital_input
* 
* The board will turn the on-board LED on or off, with a button module
*
* (c) 2013-2016 Arduino LLC.
*/

int inputPin = 6;
int ledPin = 13;

void setup() {
  pinMode(inputPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (digitalRead(inputPin) == HIGH) {
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}

Cap comentari:

Publica un comentari a l'entrada