Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rotina para controle de motor. (110v ou 220v)
- // Uso didático
- // Rui 09/05/2015
- //*************** Variaveis e constantes *************
- const int Motor = 13; // Pino de disparo do Triac
- const int Start = 4; // Entrada switch start
- const int Stop = 5; // Entrada switch stop
- const int EPO = 6; // Entrada switch EPO
- const int Sensor = 7; // Entrada switch sensor
- const int Reset = 8; // Entrada switch reset
- unsigned int debounceDelay = 50; // Tempo de debounce
- unsigned int FlagMotor;
- unsigned int FlagStart;
- unsigned int FlagEPO;
- unsigned int FlagSensor;
- //*********************** Setup ********************
- void setup()
- {
- // Serial.begin(9600); // Inicializa a serial a 9600 bps para Debug
- pinMode(Motor, OUTPUT); // Port como saída
- digitalWrite(Motor, LOW); // Desliga motor
- pinMode(Start, INPUT); // Port como entrada
- pinMode(Stop, INPUT);
- pinMode(EPO, INPUT);
- pinMode(Sensor, INPUT);
- pinMode(Reset, INPUT);
- digitalWrite(Start, HIGH); // Puul-Up Entrada
- digitalWrite(Stop, HIGH);
- digitalWrite(EPO, HIGH);
- digitalWrite(Sensor, HIGH);
- digitalWrite(Reset, HIGH);
- }
- //*********************** Loop ********************
- void loop()
- {
- // ================= Star deboucing ===================
- if(!digitalRead(Start))
- {
- delay(debounceDelay);
- if(!digitalRead(Start))
- {
- FlagStart = 1;
- while(!digitalRead(Start)) // Espera pela liberação do switch
- delayMicroseconds(1);
- }
- }
- // ================= Stop deboucing ===================
- if(!digitalRead(Stop))
- {
- delay(debounceDelay);
- if(!digitalRead(Stop))
- {
- FlagStart = 0;
- while(!digitalRead(Stop)) // Espera pela liberação do switch
- delayMicroseconds(1);
- }
- }
- // ================= EPO deboucing ===================
- if(!digitalRead(EPO))
- {
- delay(debounceDelay);
- if(!digitalRead(EPO))
- {
- FlagStart = 0;
- FlagEPO = 1;
- digitalWrite(Motor, LOW);
- while(!digitalRead(EPO)) // Espera pela liberação do switch
- delayMicroseconds(1);
- }
- }
- // ================= Sensor deboucing ===================
- if(!digitalRead(Sensor))
- {
- delay(debounceDelay);
- if(!digitalRead(Sensor))
- {
- FlagStart = 0;
- FlagSensor = 1;
- digitalWrite(Motor, LOW);
- while(!digitalRead(Sensor)) // Espera pela liberação do switch
- delayMicroseconds(1);
- }
- }
- // ================= Reset deboucing ===================
- if(!digitalRead(Reset))
- {
- delay(debounceDelay);
- if(!digitalRead(Reset))
- {
- FlagStart = 0;
- FlagEPO = 0;
- FlagSensor = 0;
- digitalWrite(Motor, LOW);
- while(!digitalRead(Reset)) // Espera pela liberação do switch
- delayMicroseconds(1);
- }
- }
- // ================= Controle ===========================
- /* //------------------ Para Debug -----------------
- Serial.print ("FlagStart ");
- Serial.println (FlagStart);
- Serial.print ("FlagEPO ");
- Serial.println (FlagEPO);
- Serial.print ("FlagSensor ");
- Serial.println (FlagSensor);
- */ //------------------ Para Debug -----------------
- if ((FlagEPO == 0)&&(FlagSensor == 0))
- {
- if (FlagStart == 1) digitalWrite(Motor, HIGH);
- else digitalWrite(Motor, LOW);
- }
- // Serial.println (" "); // Para Debug
- // delay(500); // Para Debug
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement