commit b986f5950f359615c6ef99f57b0728b681c6a810 Author: Arturo Corro Date: Wed Dec 1 17:05:35 2021 -0600 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..50a15ab --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Sistema de control de Espejos abatibles con arduino + +### Caracteristicas +- Conectado a pulso de apertura y cierre de seguros +- Basado en Arduino + + +## Diagramas de flujo + +![](https://git.koneko.mx/Koneko-EM/espejos-abatibles/raw/branch/main/images/diagrama de flujo.jpeg) + diff --git a/espejos-abatibles/espejos-abatibles.ino b/espejos-abatibles/espejos-abatibles.ino new file mode 100644 index 0000000..f89fb0f --- /dev/null +++ b/espejos-abatibles/espejos-abatibles.ino @@ -0,0 +1,212 @@ +/***************************************** +* Espejos abatibles * +* Controlado por: * +* Ignición * +* Cierre de seguros * +* 15/08/2021 * +* Versión 0.1.0 * +* koneko.mx * +*****************************************/ + +/* + PIN Uso Color Board Notas + 1 Detección de ignición Morado A3 Divisor de tención, entrada 12v + 2 Cerrar seguros Amarillo A4 SDA Divisor de tención, entrada 12v + 3 Tierra Negro GND + 4 NC Rosa A5 SCL + 5 Alimentación 9-24V Rojo VCC + 6 Abrir espejos Verde D3 INT1 PWM Optoacoplador con pulso de salida a tierra + 7 NC 5V + 8 Cerrar espejos Cafe D5 PWM Optoacoplador con pulso de salida a tierra +*/ + +#include + +/************************************************** +* Definición de Constantes +**************************************************/ + // PINOUT + #define IGNITION_PIN A3 // Morado + #define SAFETY_CLOSURE_PULSE_PIN A5 // Amarillo + #define MIRROR_CLOSURE_PIN 5 // Cafe + #define MIRROR_OPENING_PIN 3 // Verde + + // EEPROM_MEMORY ADDRESSES + #define STATUS_MIRRORS_EEPROM_POINTER_EEPROM_ADDRESS 0 + + // MEMORY ACCESS + #define ALL_SETTINGS 0 + #define STATUS_MIRRORS_EEPROM_POINTER 1 + #define MIRRORS_STATUS 2 + + // ESTADOS + #define MIRROR_CLOSED 1 + #define MIRROR_OPEN 0 + + #define ON 1 + #define OFF 0 + + // Parametros de funcionamiento + #define MILLISECONDS_OF_ACTUATORS 1900 + #define IGNITION_VALUE_MIN 32 + #define SAFETY_CLOSURE_PULSE_VALUE_MIN 230 + + +/************************************************** +* Debug +* Define DEBUG_SERIAL_ENABLE to enable debug serial. +* Comment it to disable debug serial. +**************************************************/ + #define DEBUG_SERIAL_ENABLE + + #define dbSerial Serial + + #ifdef DEBUG_SERIAL_ENABLE + #define serialPrint(a) dbSerial.print(a) + #define serialPrintln(a) dbSerial.println(a) + #define serialBegin(a) dbSerial.begin(a) + #define serialBeginWhile(a) while(!dbSerial) delay(1) + #else + #define serialPrint(a) do{}while(0) + #define serialPrintln(a) do{}while(0) + #define serialBegin(a) do{}while(0) + #define serialBeginWhile(a) do{}while(0) + #endif + + +/************************************************** +* ENVIRONMENT VARIABLES +**************************************************/ + // Estado de los espejos + uint8_t mirrors_status; + uint8_t ignition_status; + uint8_t safety_closure_pulse_status; + + // Puntero de bucle de EEPROM + uint8_t status_mirrors_eeprom_pointer; + + +/************************************************** +* Mirror Control loop methods +**************************************************/ + void Load_vars_from_eeprom_memory(uint8_t _setting) + { + switch(_setting){ + case ALL_SETTINGS: + Load_vars_from_eeprom_memory(STATUS_MIRRORS_EEPROM_POINTER); + Load_vars_from_eeprom_memory(MIRRORS_STATUS); + break; + + case STATUS_MIRRORS_EEPROM_POINTER: + status_mirrors_eeprom_pointer = EEPROM.read(STATUS_MIRRORS_EEPROM_POINTER_EEPROM_ADDRESS); + + serialPrint("status_mirrors_eeprom_pointer: "); + serialPrintln(status_mirrors_eeprom_pointer); + break; + + case MIRRORS_STATUS: + mirrors_status = EEPROM.read(status_mirrors_eeprom_pointer); + + serialPrint("mirrors_status: "); + serialPrintln(mirrors_status); + break; + } + } + + uint8_t get_ignition_status(){ + uint8_t ignition_value = digitalRead(IGNITION_PIN); + + if(ignition_value){ + serialPrint("ignition_value On"); + } + + return ignition_value? + ON: + OFF; + } + + uint8_t get_safety_closure_pulse_status(){ + uint8_t safety_closure_pulse_value = analogRead(SAFETY_CLOSURE_PULSE_PIN); + + + if(safety_closure_pulse_value > SAFETY_CLOSURE_PULSE_VALUE_MIN){ + serialPrint("safety_closure: "); + serialPrintln(safety_closure_pulse_value); + + } + + + return safety_closure_pulse_value > SAFETY_CLOSURE_PULSE_VALUE_MIN? + ON: + OFF; + } + + void set_mirrors_status(uint8_t _mirrors_status){ + EEPROM.write(status_mirrors_eeprom_pointer, _mirrors_status); + + mirrors_status = _mirrors_status; + } + + void open_mirrors(){ + serialPrintln("open_mirrors()"); + + digitalWrite(MIRROR_OPENING_PIN, HIGH); + + delay(MILLISECONDS_OF_ACTUATORS); + + digitalWrite(MIRROR_OPENING_PIN, LOW); + + set_mirrors_status(MIRROR_OPEN); + } + + void close_mirrors(){ + serialPrintln("close_mirrors()"); + + digitalWrite(MIRROR_CLOSURE_PIN, HIGH); + + delay(MILLISECONDS_OF_ACTUATORS); + + digitalWrite(MIRROR_CLOSURE_PIN, LOW); + + set_mirrors_status(MIRROR_CLOSED); + } + + // Loop principal + void ignition_listening_loop() + { + ignition_status = get_ignition_status(); + safety_closure_pulse_status = get_safety_closure_pulse_status(); + + if(ignition_status == ON && mirrors_status == MIRROR_CLOSED) + open_mirrors(); + + if(ignition_status == OFF && safety_closure_pulse_status == ON && mirrors_status == MIRROR_OPEN) + close_mirrors(); + } + + +/************************************************** +* Setup & Loops +**************************************************/ + void setup() + { + pinMode(IGNITION_PIN, INPUT); + pinMode(SAFETY_CLOSURE_PULSE_PIN, INPUT); + pinMode(MIRROR_CLOSURE_PIN, OUTPUT); + pinMode(MIRROR_OPENING_PIN, OUTPUT); + + // Salida Serial + serialBegin(57600); + serialBeginWhile(); + + //EEPROM.write(0, 1); + //EEPROM.write(1, 1); + + // Cargamos variables de la EEPROM a la ram + Load_vars_from_eeprom_memory(ALL_SETTINGS); + } + + void loop() + { + ignition_listening_loop(); + } diff --git a/images/diagrama de flujo.jpeg b/images/diagrama de flujo.jpeg new file mode 100644 index 0000000..03adb70 Binary files /dev/null and b/images/diagrama de flujo.jpeg differ