attempt 1

Dependencies:   mbed

Revision:
5:d5f2ff7ca039
Parent:
4:857d2663c894
--- a/main.cpp	Fri Mar 27 22:24:19 2015 +0000
+++ b/main.cpp	Tue Mar 31 17:42:56 2015 +0000
@@ -1,16 +1,17 @@
 #include "mbed.h"
 #include <map>
 
-//elevator I/O
 BusOut leds(LED1,LED2,LED3,LED4);
+
+//Driving motors
 PwmOut EN(p22);
 DigitalOut IN1(p30);
 DigitalOut IN2(p29);
 
 
 //p23 LEFT p24 RIGHT
-PwmOut leftDoor(p21);
-//PwmOut rightDoor(p22);
+PwmOut leftDoor(p23);
+PwmOut rightDoor(p24);
 
 InterruptIn  irIN(p16);
 
@@ -25,10 +26,14 @@
 
 //timer for row switch
 Timer t1;
+
+//Timer for floor detection
 Timer irT;
+
 //init keypad map
 map<int, int> keypadMap;
 
+
 int curFloor;  //initialize at 2
 int floorDesired = 1; //init floor buffer
 bool floors[5] = {false, false, false,false,false};
@@ -48,38 +53,28 @@
 
 float tol = 150.0;
 
-void init(){
-        /*
-        keypadMap[0x11]= 0x1;
-        keypadMap[0x12]= 0x2;
-        keypadMap[0x14]= 0x4;
-        keypadMap[0x18]= 0x0;
-        keypadMap[0x21]= 0x8;
-        keypadMap[0x22]= 0x0;
-        keypadMap[0x24]= 0x0;
-        keypadMap[0x28]= 0x0;
-        */
-        
+void init(){        
         keypadMap[0x11]= 1;
         keypadMap[0x12]= 2;
         keypadMap[0x14]= 3;
         keypadMap[0x21]= 4;
         keypadMap[0x24]= 5;
-        //keypadMap[0x24]= 0;
         }
 
+//Elevator functions
 void openDoors(){
     
     leftDoor= 0.075;                  //init door closed
-    //rightDoor= 0.125;                  //itit door closed]
+    rightDoor= 0.125;                  //itit door closed]
     
     }
 void closeDoors(){
     
     leftDoor= 0.125;                  //init door closed
-    //rightDoor= 0.075;                  //itit door closed
+    rightDoor= 0.075;                  //itit door closed
     }
 
+//Elevator movement
 void up(){
     EN = 0.6;
     IN1 = 1;
@@ -97,6 +92,7 @@
     IN2 = 0.0;
     }
     
+//Floor classification based on the time period    
 int getFloor(float period) {
         if (first - tol < period && first + tol >= period)
             return 1;
@@ -111,10 +107,12 @@
         else return 0;
     }
 
+//Interrupt In of IR wave
 void irRise() {
     irT.start();
     }
 
+//Mecahnism to detect floors with aggregation
 int aggr;
 int temp;
 int prev;
@@ -137,6 +135,7 @@
     irT.reset();
     }
 
+//Getting next floor based on Elevator Algorithm
 int getNextFloor() {
         //up
         if (direction == 1){
@@ -164,19 +163,20 @@
                 return curFloor;
             }
         else return floorDesired;
-        //else return;
 
     }
 
 int main() {
         
     init();
+    
     //Initialize rows to 0 and keypad stuff
     row1 = 0;
     row2 = 0;
     t1.start();
     int cur_input = 0x00;
     int prev_input = 0x00;
+    
     //float irPeriod = 0; 
     irIN.rise(&irRise);
     irIN.fall(&irFall);
@@ -188,8 +188,8 @@
                          
     leftDoor.period(1/freq);             
     leftDoor= 0.125;                  //init door closed
-    //rightDoor.period(1/freq);              
-    //rightDoor= 0.075;                  //itit door closed
+    rightDoor.period(1/freq);              
+    rightDoor= 0.075;                  //itit door closed
     
     int reach = 0;
     
@@ -268,7 +268,6 @@
                 
                 nextFloor = getNextFloor();
                 wait(1);
-                //pc.printf("Current Floor = %d, Next Floor = %d\r",curFloor,nextFloor);
                 reach = 1;
                 pc.printf("Current Floor = %d, Next Floor = %d, Direction = %d, Last floor input = %d\r",curFloor,nextFloor, direction, floorDesired);
                 }