martes, 26 de enero de 2016

Calibración de sensores



CÓDIGO

int ledPin=10;
int ldrPin=A1;
int potPin=A5;

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

void loop() {
  int ldrValue=analogRead(ldrPin);
  int threshold=analogRead(potPin);

  if(ldrValue>threshold){
    digitalWrite(ledPin,LOW);
  }else{
    digitalWrite(ledPin,HIGH);
  }
  delay(10);

}

LDR






código

int ledPin=10;
int ldrPin=A1;void setup() {
//nothing here
}void loop() {
int ldrValue=analogRead(ldrPin);
int ledValue=map(ldrValue,0,1023,0,255);

analogWrite(ledPin, ledValue);
delay(10);

}

escribiendo en analogico


Escribiendo en analógico 1



CÓDIGO

int ledPin = 10;
int fade = 0;

void setup() {
// nothing here
}

void loop() {
analogWrite(ledPin, fade);
delay(500);
fade = fade + 50;
if (fade > 255) fade = 0;

}

COMENTARIO
hemos cambiado :

Delay de 10 a 500
fade dẹ10 a 50