0% found this document useful (0 votes)
11 views

Codigo Arduino

This document defines constants for sensor inputs and motor outputs of an elevator system. It initializes the pin modes and defines boolean variables to track the current state. The main loop reads the sensor inputs, updates the state based on transitions between states, and sets the motor outputs accordingly to move up, down or stop based on the current state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Codigo Arduino

This document defines constants for sensor inputs and motor outputs of an elevator system. It initializes the pin modes and defines boolean variables to track the current state. The main loop reads the sensor inputs, updates the state based on transitions between states, and sets the motor outputs accordingly to move up, down or stop based on the current state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

//physical inputs

const int s1a = 3;


const int s2a = 4;
const int s3a = 13;
const int s4a = 9;
const int s5a = 8;
const int s6a = 7;
const int b1a = 12;
const int b2a = 11;
const int b3a = 10;
const int b4a = 6;
const int b5a = 5;
const int b6a = 2;

// physical outputs
const int m_up = 19; //motor up
const int m_down = 18; // motor down
const int booking = 17; // reserva
const int booking1 = 16; // reserva

// Memories
//ETAPA
boolean e0 = false;
boolean e1 = false;
boolean e2 = false;
boolean e3 = false;
boolean e4 = false;
boolean e5 = false;
boolean e6 = false;

//TRANSITION
boolean t01 = false;
boolean t02 = false;
boolean t03 = false;
boolean t04 = false;
boolean t05 = false;
boolean t06 = false;
boolean t10 = false;
boolean t20 = false;
boolean t30 = false;
boolean t40 = false;
boolean t50 = false;
boolean t60 = false;

void setup() {
//sensores de piso
pinMode(s1a, INPUT);
pinMode(s2a, INPUT);
pinMode(s3a, INPUT);
pinMode(s4a, INPUT);
pinMode(s5a, INPUT);
pinMode(s6a, INPUT);
//pusadores de llamada
pinMode(b1a, INPUT);
pinMode(b2a, INPUT);
pinMode(b3a, INPUT);
pinMode(b4a, INPUT);
pinMode(b5a, INPUT);
pinMode(b6a, INPUT);
//salidas motor
pinMode(m_up, OUTPUT);
pinMode(m_down, OUTPUT);
pinMode(booking, OUTPUT);
pinMode(booking1, OUTPUT);
//ouputs low!
digitalWrite(m_up, 0);
digitalWrite(m_down, 0);
digitalWrite(booking, 0);
digitalWrite(booking1, 0);
delay(2000);

void loop() {
//Inputs
int s1 = digitalRead(s1a);
int s2 = digitalRead(s2a);
int s3 = digitalRead(s3a);
int s4 = digitalRead(s4a);
int s5 = digitalRead(s5a);
int s6 = digitalRead(s6a);
int b1 = digitalRead(b1a);
int b2 = digitalRead(b2a);
int b3 = digitalRead(b3a);
int b4 = digitalRead(b4a);
int b5 = digitalRead(b5a);
int b6 = digitalRead(b6a);

//INICIALIZACION***************************
if ((!e1 && !e2 && !e3 && !e4 && !e5 && !e6) == true) {
e0 = true;
}
//TRANSITION*********************************
//from 1 to 2 floor
if (e0 && s1 && b2 == true) {
t01 = true;
t10 = false;
}
if (e1 && s2 == true) {
t10 = true;
t01 = false;
}
//from 1 to 3 floor
if (e0 && s1 && b3 == true) {
t02 = true;
t20 = false;
}
if (e2 && s3 == true) {
t20 = true;
t02 = false;
}
//from 2 to 3 floor
if (e0 && s2 && b3 == true) {
t03 = true;
t30 = false;
}
if (e3 && s3 == true) {
t30 = true;
t03 = false;
}
//from 3 to 2 floor
if (e0 && s3 && b2 == true) {
t04 = true;
t40 = false;
}
if (e4 && s2 == true) {
t40 = true;
t04 = false;
}
//from 3 to 1 floor
if (e0 && s3 && b1 == true) {
t05 = true;
t50 = false;
}
if (e5 && s1 == true) {
t50 = true;
t05 = false;
}
//from 2 to 1 floor
if (e0 && s2 && b1 == true) {
t06 = true;
t60 = false;
}
if (e6 && s1 == true) {
t60 = true;
t06 = false;
}

//ETAPA**************************************
if (e0 && t01 == true) {
e0 = false;
e1 = true;
}
if (e1 && t10 == true) {
e1 = false;
e0 = true;
}

if (e0 && t02 == true) {


e0 = false;
e2 = true;
}
if (e2 && t20 == true) {
e2 = false;
e0 = true;
}

if (e0 && t03 == true) {


e0 = false;
e3 = true;
}
if (e3 && t30 == true) {
e3 = false;
e0 = true;
}
if (e0 && t04 == true) {
e0 = false;
e4 = true;
}
if (e4 && t40 == true) {
e4 = false;
e0 = true;
}

if (e0 && t05 == true) {


e0 = false;
e5 = true;
}
if (e5 && t50 == true) {
e5 = false;
e0 = true;
}

if (e0 && t06 == true) {


e0 = false;
e6 = true;
}
if (e6 && t60 == true) {
e6 = false;
e0 = true;
}

//ACTUADORES*********************************
// Motor subiendo
if (e1 || e2 || e3 == true) {
digitalWrite(m_up, HIGH);
digitalWrite(m_down, LOW);
}
//Reposo
if (e0 == true) {
digitalWrite(m_up, LOW);
digitalWrite(m_down, LOW);
}
//motor bajando
if (e4 || e5 || e6 == true) {
digitalWrite(m_up, LOW);
digitalWrite(m_down, HIGH);
}
}

You might also like