Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //INPUTS
- const int boton_subir = 4;
- int valor_boton_subir;
- bool subir_presionado;
- bool subir;
- int anterior_subir = 3;
- const int sensor_superior = 2;
- const int sensor_inferior = 3;
- const int boton_bajar = 5;
- const int automatico = 1;
- //const int laser = 6;
- //const int sensor_mesa = 10;
- //
- //const int contador_arriba = 8;
- //const int contador_abajo = 9;
- //OUTPUTS
- const int bajar_motor = 12;
- const int subir_motor = 11;
- int valor_sensor_superior;
- int valor_sensor_inferior;
- int valor_boton_bajar;
- int valor_automatico;
- int anterior_sensor_superior = 3;
- int anterior_sensor_inferior = 3;
- int anterior_boton_bajar = 3;
- int anterior_automatico = 3;
- //int valor_laser;
- //int valor_sensor_mesa;
- //
- //int valor_contador_arriba;
- //int valor_contador_abajo;
- //int valor_subir_motor;
- //int valor_bajar_motor;
- void setup()
- {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(sensor_superior, INPUT);
- pinMode(sensor_inferior, INPUT);
- pinMode(boton_subir, INPUT);
- pinMode(boton_bajar, INPUT);
- pinMode(subir_motor, OUTPUT);
- pinMode(bajar_motor, OUTPUT);
- //pinMode(laser, INPUT);
- //pinMode(automatico, INPUT);
- //pinMode(sensor_mesa, INPUT);
- }
- void leerValores()
- {
- //leer input subir elevador
- valor_boton_subir = digitalRead(boton_subir);
- if (valor_boton_subir == 1)
- {
- subir_presionado = true;
- }
- else
- {
- if (subir_presionado == true)
- {
- if (subir == false)
- {
- subir = true;
- }
- else
- {
- subir = false;
- }
- subir_presionado = false;
- }
- }
- //leer input bajar elevador
- valor_boton_bajar = digitalRead(boton_bajar);
- //leer input sensor superior
- valor_sensor_superior = digitalRead(sensor_superior);
- //leer input sensor superior
- valor_sensor_inferior = digitalRead(sensor_inferior);
- ////leer laser de proximidad 1/0
- //valor_laser = digitalRead(laser);
- ////leer input boton modo automatico
- valor_automatico = digitalRead(automatico);
- ////leer input sensor superior
- //valor_sensor_mesa = digitalRead(sensor_mesa);
- }
- void imprimirValores()
- {
- if (subir != anterior_subir)
- {
- Serial.println("subir: ");
- Serial.println(subir);
- Serial.println("\n");
- anterior_subir = subir;
- }
- /*if (valor_boton_bajar != anterior_boton_bajar)
- {
- Serial.println("valor_boton_bajar: ");
- Serial.println(valor_boton_bajar);
- Serial.println("\n");
- anterior_boton_bajar = valor_boton_bajar;
- }
- if (valor_sensor_superior != anterior_sensor_superior)
- {
- Serial.println("valor_sensor_superior: ");
- Serial.println(valor_sensor_superior);
- Serial.println("\n");
- anterior_sensor_superior = valor_sensor_superior;
- }
- if (valor_sensor_inferior != anterior_sensor_inferior)
- {
- Serial.println("valor_sensor_inferior: ");
- Serial.println(valor_sensor_inferior);
- Serial.println("\n");
- anterior_sensor_inferior = valor_sensor_inferior;
- }
- if (valor_automatico != anterior_automatico)
- {
- Serial.println("valor_automatico: ");
- Serial.println(valor_automatico);
- Serial.println("\n");
- anterior_automatico = valor_automatico;
- }*/
- }
- void subirMotor()
- {
- //si no ah llegado al sensor superior
- if (valor_sensor_superior == 0)
- {
- //subir motor
- digitalWrite(subir_motor, true);
- }
- else
- {
- digitalWrite(subir_motor, false);
- }
- }
- void bajarMotor()
- {
- //si no ah llegado al sensor inferior
- if (valor_sensor_inferior == 0)
- {
- //bajar motor
- digitalWrite(bajar_motor, true);
- }
- else
- {
- digitalWrite(bajar_motor, false);
- }
- }
- void moverManual()
- {
- //if (valor_automatico == 0)
- //{
- //si esta activo el boton de subir
- if (subir == true)
- {
- subirMotor();
- }
- else
- {
- digitalWrite(subir_motor, false);
- }
- //si esta activo el boton de bajar
- /* if (valor_boton_bajar == 1)
- {
- bajarMotor();
- }
- else
- {
- digitalWrite(bajar_motor, false);
- }*/
- //}
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- leerValores();
- imprimirValores();
- moverManual();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement