miércoles, 6 de marzo de 2013

Compensación de iluminación (Arduino + LDR). Fuente: Arduteka.




CÓDIGO:

//Aquí almacenamos los datos recogidos del LDR:
int valorLDR = 0;

//Decimos que pines vamos a utilizar para LED
int pinLed1 = 12;
int pinLed2 = 11;
int pinLed3 = 10;
int pinLed4 = 9;
int pinLed5 = 8;

//Y que pin para la LDR
int pinLDR = 0;

void setup()
{
  //Establecemos como salida los pines para LED
  pinMode(pinLed1, OUTPUT);
  pinMode(pinLed2, OUTPUT);
  pinMode(pinLed3, OUTPUT);
  pinMode(pinLed4, OUTPUT);
  pinMode(pinLed5, OUTPUT);

  //Le decimos que vamos a usar una referencia externa
  analogReference(EXTERNAL);

}

void loop()
{
  //Guardamos el valor leido en una variable
  valorLDR = analogRead(pinLDR);

  //Y comenzamos las comparaciones:
  if(valorLDR >= 1023)
  {
    digitalWrite(pinLed1, LOW);
    digitalWrite(pinLed2, LOW);
    digitalWrite(pinLed3, LOW);
    digitalWrite(pinLed4, LOW);
    digitalWrite(pinLed5, LOW);
  }
  else if((valorLDR >= 823) & (valorLDR < 1023))
  {
    digitalWrite(pinLed1, HIGH);
    digitalWrite(pinLed2, LOW);
    digitalWrite(pinLed3, LOW);
    digitalWrite(pinLed4, LOW);
    digitalWrite(pinLed5, LOW);
  }
  else if((valorLDR >= 623) & (valorLDR < 823))
  {
    digitalWrite(pinLed1, HIGH);
    digitalWrite(pinLed2, HIGH);
    digitalWrite(pinLed3, LOW);
    digitalWrite(pinLed4, LOW);
    digitalWrite(pinLed5, LOW);
  }
  else if((valorLDR >= 423) & (valorLDR < 623))
  {
    digitalWrite(pinLed1, HIGH);
    digitalWrite(pinLed2, HIGH);
    digitalWrite(pinLed3, HIGH);
    digitalWrite(pinLed4, LOW);
    digitalWrite(pinLed5, LOW);
  }
  else  if((valorLDR >= 223) & (valorLDR < 423))
  {
    digitalWrite(pinLed1, HIGH);
    digitalWrite(pinLed2, HIGH);
    digitalWrite(pinLed3, HIGH);
    digitalWrite(pinLed4, HIGH);
    digitalWrite(pinLed5, LOW);
  }
  else
  {
    digitalWrite(pinLed1, HIGH);
    digitalWrite(pinLed2, HIGH);
    digitalWrite(pinLed3, HIGH);
    digitalWrite(pinLed4, HIGH);
    digitalWrite(pinLed5, HIGH);
  }

}

martes, 5 de marzo de 2013

Contador de 0 a 99 con ARDUINO UNO rev.3 y Displays de 7 Segmentos LSD5365 (Ánodo Común).


CÓDIGO:

int a = 0;
int D1_segmento_a=0; 
int D1_segmento_b=1; 

void setup()
{
 
pinMode(D1_segmento_a,OUTPUT);
pinMode(D1_segmento_b,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);

}

void loop()
{

if (a==0)

//numero 0
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
}

//numero 0
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,LOW);
digitalWrite(D1_segmento_a,LOW);
delay(500);

//numero 1
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,HIGH);
digitalWrite(D1_segmento_a,HIGH);
delay(500);

//numero 2
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
digitalWrite(3,LOW);
digitalWrite(2,HIGH);
digitalWrite(D1_segmento_b,LOW);
digitalWrite(D1_segmento_a,LOW);
delay(500);

//numero 3
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,LOW);
digitalWrite(D1_segmento_a,HIGH);
delay(500);

//numero 4
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,HIGH);
digitalWrite(D1_segmento_a,HIGH);
delay(500);

//numero 5
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,LOW);
digitalWrite(D1_segmento_a,HIGH);
delay(500);

//numero 6
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,LOW);
digitalWrite(D1_segmento_a,LOW);
delay(500);

//numero 7
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,HIGH);
digitalWrite(D1_segmento_a,HIGH);
delay(500);

//numero 8
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,LOW);
digitalWrite(D1_segmento_a,LOW);
delay(500);

//numero 9
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
digitalWrite(D1_segmento_b,HIGH);
digitalWrite(D1_segmento_a,HIGH);
delay(500);



a=a+1;

if (a==1)
{

 //numero 1
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
 
}

if (a==2)
{

//numero 2
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
 
}

if (a==3)
{

//numero 3
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,HIGH);
 
}

if (a==4)
{

//numero 4
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
 
}

if (a==5)
{
 
//numero 5
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,HIGH);
 
}

if (a==6)
{

//numero 6
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
 
}

if (a==7)
{

//numero 7
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
 
}

if (a==8)
{

//numero 8
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
 
}

if (a==9)
{

 //numero 9
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);

a=0;
 
}


}

domingo, 3 de marzo de 2013

Contador de 0 a 9 con ARDUINO UNO rev.3 y Display 7 Segmentos LSD5365 (Ánodo Común).



void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
}

void loop()
{
//numero 1
digitalWrite(8,LOW);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
delay(250);

//numero 2
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
delay(250);

//numero 3
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,HIGH);
delay(250);

//numero 4
digitalWrite(8,LOW);
digitalWrite(7,HIGH);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
delay(250);

//numero 5
digitalWrite(8,HIGH);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,HIGH);
delay(250);

//numero 6
digitalWrite(8,HIGH);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
delay(250);

//numero 7
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
delay(250);

//numero 8
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
delay(250);

//numero 9
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
delay(250);

//numero 0
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(3,LOW);
digitalWrite(2,LOW);
delay(250);

}