Programacion de Sistemas - 2015 Diseño de un parking controlado por Arduino





#include HttpClient.h
#include Bridge.h
//Declaracion de variables globales
int numero = 0;
int estadoBoton1 = 0;
int estadoBoton2 = 0;
const int PIRPin= 4;
int vector [10]={0,0,0,0,0,0,0,0,0,0};
int value=0;
int calibrationTime = 10;
bool actua;

HttpClient client;


void setup() {
Serial.begin(9600);
Bridge.begin();

pinMode(2, INPUT);
pinMode(3, INPUT);
//pinMode(4, INPUT);
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);
pinMode(PIRPin, INPUT);
digitalWrite(PIRPin, LOW);
//Calibracion del sensor PIR
Serial.print(" calibrando sensor ");
for(int i = 0; i < calibrationTime; i++){
delay(1000);
}
delay(50);
}
void loop() {
estadoBoton1 = digitalRead(2);
estadoBoton2 = digitalRead(3);
value= digitalRead(PIRPin);
//Control de los botones pulsados
if (estadoBoton1 == HIGH and numero < 9) {
numero = numero + 1;
delay(100);
}
else
if (estadoBoton2 == HIGH and numero > 0) {
numero = numero - 1;
delay(100);
}
actua=false;
while (!actua){
if (vector[numero] == 0){
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
actua=true;
}
else
if (vector[numero] == 1){
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
actua=true;
}
}
//Cuando SensorPir recibe movimientpo
if (value == HIGH)
{
Serial.print("entra porque value = HIGH");
delay(2750);
if (vector[numero] == 0){
vector[numero] = 1;
//Actualiza la pagina web
String stringnum(numero,10);
String stringEst (vector[numero],10);
client.get("http://progsist.3eeweb.com/funcionupdates.php?numero="
+ stringnum + "&estado="+ stringEst + "&color=FF0000");
}
else
if (vector[numero] == 1){
vector[numero]= 0;
//Actualiza la web
String stringnum(numero,10);
String stringEst (vector[numero],10);
client.get("http://progsist.3eeweb.com/funcionupdates.php?numero="+
stringnum + "&estado="+ stringEst + "&color=64FE2E");
}
delay(2750);
value=LOW;
}

else {}

//Sacar los números en el display

switch (numero) {
case 0:
limpiar();
cero();
break;
case 1:
limpiar();
uno();
break;
case 2:
limpiar();
dos();
break;
case 3:
limpiar();
tres();
break;
case 4:
limpiar();
cuatro();
break;
case 5:
limpiar();
cinco();
break;
case 6:
limpiar();
seis();
break;
case 7:
limpiar();
siete();
break;
case 8:
limpiar();
ocho();
break;
case 9:
limpiar();
nueve();
break;

}

delay(125);

}

void cero(){
digitalWrite(10,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}

void uno(){
digitalWrite(8,HIGH);
digitalWrite(5,HIGH);
}
void dos(){
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(11,HIGH);
}
void tres(){
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
digitalWrite(11,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}
void cuatro(){
digitalWrite(8,HIGH);
digitalWrite(5,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
}
void cinco(){
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
}
void seis(){
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);

}
void siete(){
digitalWrite(8,HIGH);
digitalWrite(5,HIGH);
digitalWrite(9,HIGH);

}
void ocho(){

digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
}
void nueve(){

digitalWrite(5,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
}

void limpiar(){
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}