178
#include <AFMotor.h> AF_Stepper motor_freight(200, 1); AF_Stepper motor_passenger(200, 2); void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!"); motor_freight.setSpeed(80); // 60 rpm motor_passenger.setSpeed(100); } void loop() { motor_freight.step(1, FORWARD, SINGLE); motor_passenger.step(1, FORWARD, SINGLE); // motor_freight.step(100, BACKWARD, SINGLE); // delay(500); // motor_passenger.step(200, FORWARD, SINGLE); // delay(500); }

Elevator Programming Code

  • Upload
    100mph

  • View
    1.269

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Elevator Programming Code

#include <AFMotor.h>

AF_Stepper motor_freight(200, 1);AF_Stepper motor_passenger(200, 2);

void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!");

motor_freight.setSpeed(80); // 60 rpm motor_passenger.setSpeed(100);

}

void loop() { motor_freight.step(1, FORWARD, SINGLE); motor_passenger.step(1, FORWARD, SINGLE);// motor_freight.step(100, BACKWARD, SINGLE); // delay(500); // motor_passenger.step(200, FORWARD, SINGLE); // delay(500); }

Page 2: Elevator Programming Code

#include <AFMotor.h>

AF_Stepper motor_freight(200, 1);AF_Stepper motor_passenger(200, 2);

void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!");

motor_freight.setSpeed(60); // 60 rpm motor_passenger.setSpeed(80);

}

void loop() { motor_freight.step(300, FORWARD, SINGLE); delay(500); motor_freight.step(100, BACKWARD, SINGLE); delay(500); motor_passenger.step(200, FORWARD, SINGLE); delay(500); motor_passenger.step(200, BACKWARD, SINGLE); delay(500);

}

Page 3: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

#include <avr/io.h>#include "WProgram.h"#include "AFMotor.h"

static uint8_t latch_state;

AFMotorController::AFMotorController(void) {}

void AFMotorController::enable(void) { // setup the latch LATCH_DDR |= _BV(LATCH); ENABLE_DDR |= _BV(ENABLE); CLK_DDR |= _BV(CLK); SER_DDR |= _BV(SER); latch_state = 0;

latch_tx(); // "reset"

ENABLE_PORT &= ~_BV(ENABLE); // enable the chip outputs!}

void AFMotorController::latch_tx(void) { uint8_t i;

LATCH_PORT &= ~_BV(LATCH); SER_PORT &= ~_BV(SER); for (i=0; i<8; i++) { CLK_PORT &= ~_BV(CLK); if (latch_state & _BV(7-i)) SER_PORT |= _BV(SER); else SER_PORT &= ~_BV(SER); CLK_PORT |= _BV(CLK); } LATCH_PORT |= _BV(LATCH);}

static AFMotorController MC;

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (1 of 8) [26/04/08 4:33:39 PM]

Page 4: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

/****************************************** MOTORS******************************************/

AF_DCMotor::AF_DCMotor(uint8_t num, uint8_t freq) { motornum = num; pwmfreq = freq;

MC.enable();

switch (num) { case 1: latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B); // set both motor pins to 0 MC.latch_tx(); // use PWM from timer2A TCCR2A |= _BV(COM2A1) | _BV(WGM20) | _BV(WGM21); // fast PWM, turn on oc0 TCCR2B = freq & 0x7; OCR2A = 0; DDRB |= _BV(3); break; case 2: latch_state &= ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // set both motor pins to 0 MC.latch_tx(); // use PWM from timer2B TCCR2A |= _BV(COM2B1) | _BV(WGM20) | _BV(WGM21); // fast PWM, turn on oc0a TCCR2B = _BV(CS22); // clk/256*64 = ~1Khz TCCR2B = freq & 0x7; DDRD |= _BV(3); break; case 3: latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B); // set both motor pins to 0 MC.latch_tx(); // use PWM from timer0B TCCR0A |= _BV(COM0B1) | _BV(WGM00) | _BV(WGM01); // fast PWM, turn on oc0a TCCR0B = freq & 0x7; OCR0B = 0; DDRD |= _BV(5); break; case 4:

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (2 of 8) [26/04/08 4:33:39 PM]

Page 5: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

latch_state &= ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // set both motor pins to 0 MC.latch_tx(); // use PWM from timer0A TCCR0A |= _BV(COM0A1) | _BV(WGM00) | _BV(WGM01); // fast PWM, turn on oc0a TCCR0B = freq & 0x7; OCR0A = 0; DDRD |= _BV(6); break; }}

void AF_DCMotor::run(uint8_t cmd) { uint8_t a, b; switch (motornum) { case 1: a = MOTOR1_A; b = MOTOR1_B; break; case 2: a = MOTOR2_A; b = MOTOR2_B; break; case 3: a = MOTOR3_A; b = MOTOR3_B; break; case 4: a = MOTOR4_A; b = MOTOR4_B; break; default: return; } switch (cmd) { case FORWARD: latch_state |= _BV(a); latch_state &= ~_BV(b); MC.latch_tx(); break; case BACKWARD: latch_state &= ~_BV(a); latch_state |= _BV(b); MC.latch_tx(); break; case RELEASE: latch_state &= ~_BV(a); latch_state &= ~_BV(b); MC.latch_tx(); break;

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (3 of 8) [26/04/08 4:33:39 PM]

Page 6: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

}}

void AF_DCMotor::setSpeed(uint8_t speed) { switch (motornum) { case 1: OCR2A = speed; break; case 2: OCR2B = speed; break; case 3: OCR0B = speed; break; case 4: OCR0A = speed; break; }}

/****************************************** STEPPERS******************************************/

AF_Stepper::AF_Stepper(uint16_t steps, uint8_t num) { MC.enable();

revsteps = steps; steppernum = num;

if (steppernum == 1) { latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B) & ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // all motor pins to 0 MC.latch_tx(); // do not use PWM! TCCR2B = 0; // turn off PWM OCR2A = 0;

// enable both H bridges DDRD |= _BV(3); PORTD |= _BV(3); DDRB |= _BV(3); PORTB |= _BV(3); } else if (steppernum == 2) { latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B) & ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // all motor pins to 0

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (4 of 8) [26/04/08 4:33:39 PM]

Page 7: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

MC.latch_tx(); // do not use PWM! TCCR0B = 0; // turn off PWM OCR0A = 0; // enable both H bridges DDRD |= _BV(5) | _BV(6); PORTD |= _BV(5) | _BV(6); }}

void AF_Stepper::setSpeed(uint16_t rpm) { usperstep = 60000000 / (revsteps * rpm); steppingcounter = 0;}

void AF_Stepper::release(void) { if (steppernum == 1) { latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B) & ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // all motor pins to 0 MC.latch_tx(); } else if (steppernum == 2) { latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B) & ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // all motor pins to 0 MC.latch_tx(); }}

void AF_Stepper::step(uint16_t steps, uint8_t dir, uint8_t style) { uint32_t uspers = usperstep; if (style == INTERLEAVE) { uspers /= 2; }

while (steps--) { onestep(dir, style); delay(uspers/1000); // in ms steppingcounter += (uspers % 1000); if (steppingcounter >= 1000) { delay(1); steppingcounter -= 1000; }

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (5 of 8) [26/04/08 4:33:39 PM]

Page 8: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

}}

void AF_Stepper::onestep(uint8_t dir, uint8_t style) { uint8_t a, b, c, d; uint8_t step;

if (steppernum == 1) { a = _BV(MOTOR1_A); b = _BV(MOTOR2_A); c = _BV(MOTOR1_B); d = _BV(MOTOR2_B); } else if (steppernum == 2) { a = _BV(MOTOR3_A); b = _BV(MOTOR4_A); c = _BV(MOTOR3_B); d = _BV(MOTOR4_B); } else { return; }

// OK next determine what step we are at if ((latch_state & (a | b)) == (a | b)) step = 1; else if ((latch_state & (b | c)) == (b | c)) step = 3; else if ((latch_state & (c | d)) == (c | d)) step = 5; else if ((latch_state & (d | a)) == (d | a)) step = 7; else if (latch_state & a) step = 0; else if (latch_state & b) step = 2; else if (latch_state & c) step = 4; else step = 6;

// next determine what sort of stepping procedure we're up to if (style == SINGLE) { if (step % 2) { // we're at an odd step, weird

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (6 of 8) [26/04/08 4:33:39 PM]

Page 9: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

if (dir == FORWARD) step = (step + 1) % 8; else step = (step + 7) % 8; } else { // go to the next even step if (dir == FORWARD) step = (step + 2) % 8; else step = (step + 6) % 8; } } else if (style == DOUBLE) { if (! (step % 2)) { // we're at an even step, weird if (dir == FORWARD) step = (step + 1) % 8; else step = (step + 7) % 8; } else { // go to the next odd step if (dir == FORWARD) step = (step + 2) % 8; else step = (step + 6) % 8; } } else if (style == INTERLEAVE) { if (dir == FORWARD) step = (step + 1) % 8; else step = (step + 7) % 8; } // release all latch_state &= ~a & ~b & ~c & ~d; // all motor pins to 0 switch (step) { case 0: latch_state |= a; // energize coil 1 only break; case 1: latch_state |= a | b; // energize coil 1+2 break; case 2: latch_state |= b; // energize coil 2 only break; case 3: latch_state |= b | c; // energize coil 2+3

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (7 of 8) [26/04/08 4:33:39 PM]

Page 10: Elevator Programming Code

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt

break; case 4: latch_state |= c; // energize coil 3 only break; case 5: latch_state |= c | d; // energize coil 3+4 break; case 6: latch_state |= d; // energize coil 4 only break; case 7: latch_state |= d | a; // energize coil 1+4 break; } MC.latch_tx();}

file:///Users/mg/Documents/M2%20Thesis%202008/Tech/03%20Arduino%20Code%20/AFMotornoservo.txt (8 of 8) [26/04/08 4:33:39 PM]

Page 11: Elevator Programming Code

// H Bridge Trouble Shooting

int motorPin1 = 8;int motorPin2 = 9;int motorPin3 = 10;int motorPin4 = 11;int ledPin = 13;int delayTime = 1000;

void setup() { pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); pinMode(ledPin, OUTPUT);

}

void loop() { digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second}

Page 12: Elevator Programming Code
Page 13: Elevator Programming Code

// H bridge Trouble Shooting B

int motorPin1 = 8;int motorPin2 = 9;int motorPin3 = 10;int motorPin4 = 11;int ledPin = 13;int delayTime = 10;

void setup() { pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); pinMode(ledPin, OUTPUT);

}

void loop() { digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); digitalWrite(ledPin, HIGH); // sets the LED on delay(1); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1); // waits for a second}

Page 14: Elevator Programming Code
Page 15: Elevator Programming Code

// Igoe Code modified

#include <Stepper.h>

/* Stepper Motor Controller language: Wiring/Arduino

This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 and 9 of the Arduino.

The motor moves 100 steps in one direction, then 100 in the other.

Created 11 Mar. 2007 Modified 7 Apr. 2007 by Tom Igoe

*/

// define the pins that the motor is attached to. You can use// any digital I/O pins.

#include <Stepper.h>

#define motorSteps 50 // change this depending on the number of steps // per revolution of your motor#define motorPin1 8#define motorPin2 9#define motorPin3 7#define motorPin4 6#define ledPin 13

// initialize of the Stepper library:Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

void setup() { // set the motor speed at 60 RPMS: myStepper.setSpeed(120);

// Initialize the Serial port: Serial.begin(9600);

// set up the LED pin: pinMode(ledPin, OUTPUT); // blink the LED: blink(3);}

void loop() { // Step forward 100 steps: Serial.println("Forward"); myStepper.step(100); delay(500);

Page 16: Elevator Programming Code

// Step backward 100 steps: Serial.println("Backward"); myStepper.step(-100); delay(500);

}

// Blink the reset LED:void blink(int howManyTimes) { int i; for (i=0; i< howManyTimes; i++) { digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); delay(200); }}

Page 17: Elevator Programming Code

// 15 March Shift Register B//define where your pins areint latchPin = 7;int dataPin = 8;int clockPin = 9;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //01001000

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); if (switchVar1 > 0)//{digitalWrite(ledPin,1);//delay(1000);//digitalWrite (ledPin,0);//} //Print out the results. //leading 0's at the top of the byte //(7, 6, 5, etc) will be dropped before //the first pin that has a high input //reading Serial.println(switchVar1, BIN);

//white spaceSerial.println("Marnie");//delay so all these print satements can keep up.

Page 18: Elevator Programming Code

delay(500);

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println();

Page 19: Elevator Programming Code

//Serial.println(myDataIn, BIN); return myDataIn;}

Page 20: Elevator Programming Code
Page 21: Elevator Programming Code

//15 March Shift Register 1

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //01001000

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); if (switchVar1 == 1){digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);} //Print out the results. //leading 0's at the top of the byte //(7, 6, 5, etc) will be dropped before //the first pin that has a high input //reading Serial.println(switchVar1, BIN);

//white space

Page 22: Elevator Programming Code

Serial.println("Marnie");//delay so all these print satements can keep up. delay(500);

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

}

Page 23: Elevator Programming Code

//debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 24: Elevator Programming Code
Page 25: Elevator Programming Code

// 1 April Shift Register Trials A

//define where your pins areint latchPin = 8;int dataPin = 9;int clockPin = 7;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the dayint floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); if (switchVar1 == 1) {floorcount = 1;} else if (switchVar1 == 2) {floorcount = 2; //else if (switchVar1 == 4)// {floorcount = 3;// else if (switchVar1 = 8)// {floorcount = 4;}// else if (switchVar1 = 16)// {floorcount = 5;}

Page 26: Elevator Programming Code

// else if (switchVar1 = 32)// {floorcount = 6;}// else if (switchVar1 = 64)// {floorcount = 7;}// else if (switchVar1 = 128)// {floorcount = 8;}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

Page 27: Elevator Programming Code

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 28: Elevator Programming Code
Page 29: Elevator Programming Code

// 1 April Shift Register Trials A1

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 159;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); //switchVar2 = shiftIn(dataPin, clockPin);

if (switchVar1 == 1) {floorcount = 1; // else if (switchVar1 == 2)// {floorcount = 2;}// else if (switchVar1 == 4)// {floorcount = 3;}// else if (switchVar1 == 8)// {floorcount = 4;}

Page 30: Elevator Programming Code

// else if (switchVar1 == 16)// {floorcount = 5;}// else if (switchVar1 == 32)// {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7;}// else if (switchVar1 == 128)// {floorcount = 8;}

// else if (switchVar2 == 1)// {//floorcount = freight move up until released;// }// else if (switchVar2 == 2)// {//floorcount = freight move down until released;// }// else if (switchVar2 == 4)// {//elevator_loveletter;//}// else if (switchVar2 == 8)// {//big_brother;//}// else if (switchVar2 == 16)// {//bureaucratic_prostitution;//}// else if (switchVar2 == 32)// {//coordinates_of_social_space;//}// else if (switchVar2 == 64)// {//entrapment;//} //else if (switchVar2 == 128)// {//the_fear;//}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0;

Page 31: Elevator Programming Code

int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 32: Elevator Programming Code
Page 33: Elevator Programming Code

// 1 April Shift Register Trial B

//define where your pins areint latchPin = 8;int dataPin = 9;int clockPin = 7;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the dayint floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); if (switchVar1 == 1) {floorcount = 1;} //else if (switchVar1 == 2) //{floorcount = 2;} //else if (switchVar1 == 4)// {floorcount = 3;}// else if (switchVar1 = 8)// {floorcount = 4;}// else if (switchVar1 = 16)// {floorcount = 5;}

Page 34: Elevator Programming Code

// else if (switchVar1 = 32)// {floorcount = 6;}// else if (switchVar1 = 64)// {floorcount = 7;}// else if (switchVar1 = 128)// {floorcount = 8;}// else if (switchVar1 = 256)// {floorcount = freight move up until released;}// else if (switchVar1 = 512)// {floorcount = freight move down until released;}// else if (switchVar1 = 1024) // {elevator_loveletter;}// else if (switchVar1 = 2048) // {big_brother;}// else if (switchVar1 = 4096) // do {bureaucratic_prostitution;} // else if (switchVar1 = 8192) // do {coordinates_of_social_space;} //else if (switchvar1 = 16384) // {entrapment;} // else if (switchvar1 = 32768) //{the_fear;} }

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift

Page 35: Elevator Programming Code

//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 36: Elevator Programming Code
Page 37: Elevator Programming Code

// 3 April Shift Register Trail A

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 159;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); switchVar2 = shiftIn(dataPin, clockPin);

if (switchVar1 == 1) {floorcount = 1;} else if (switchVar1 == 2) {floorcount = 2;} else if (switchVar1 == 4) {floorcount = 3;} else if (switchVar1 == 8) {floorcount = 4;}

Page 38: Elevator Programming Code

else if (switchVar1 == 16) {floorcount = 5;} else if (switchVar1 == 32) {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7;}// else if (switchVar1 == 128)// {floorcount = 8;}

else if (switchVar2 > 255) {//floorcount = freight move up until released; // else if (switchVar2 == 2) //{//floorcount = freight move down until released;// }// else if (switchVar2 == 4) // {//elevator_loveletter;//}// else if (switchVar2 == 8) //{//big_brother;//} //else if (switchVar2 == 16) //{//bureaucratic_prostitution;//} //else if (switchVar2 == 32) //{//coordinates_of_social_space; //} //else if (switchVar2 == 64) //{//entrapment; //} //else if (switchVar2 == 128) //{//the_fear; //}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;

Page 39: Elevator Programming Code

int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 40: Elevator Programming Code
Page 41: Elevator Programming Code

// 4 April Shift Register A

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 7;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 159;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); switchVar2 = shiftIn(dataPin, clockPin);

if (switchVar1 == 1) {floorcount = 1;} else if (switchVar1 == 2) {floorcount = 2;} else if (switchVar1 == 4) {floorcount = 3;} else if (switchVar1 == 8) {floorcount = 4;}

Page 42: Elevator Programming Code

else if (switchVar1 == 16) {floorcount = 5;} else if (switchVar1 == 32) {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7;}// else if (switchVar1 == 128)// {floorcount = 8;}

else if (switchVar2 == 1) {//floorcount = freight move up until released; } else if (switchVar2 == 2) {//floorcount = freight move down until released; } else if (switchVar2 == 4) {//elevator_loveletter;} else if (switchVar2 == 8) {//big_brother;} else if (switchVar2 == 16) {//bureaucratic_prostitution;} else if (switchVar2 == 32) {//coordinates_of_social_space; } else if (switchvar2 == 64) {//entrapment; } else if (switchvar2 == 128) {//the_fear; }

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;

Page 43: Elevator Programming Code

int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 44: Elevator Programming Code
Page 45: Elevator Programming Code

// 6 April Shift Register Trial

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 159;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); switchVar2 = shiftIn(dataPin, clockPin);

if (switchVar1 == 1) {floorcount = 1;} else if (switchVar1 == 2) {floorcount = 2;} else if (switchVar1 == 4) {floorcount = 3;} else if (switchVar1 == 8) {floorcount = 4;}

Page 46: Elevator Programming Code

else if (switchVar1 == 16) {floorcount = 5;} else if (switchVar1 == 32) {floorcount = 6;} else if (switchVar1 == 64) {floorcount = 7;}// else if (switchVar1 == 128)// {floorcount = 8;}

else if (switchVar2 == 1) {//floorcount = freight move up until released; } else if (switchVar2 == 2) {//floorcount = freight move down until released; } else if (switchVar2 == 4) {//elevator_loveletter;} else if (switchVar2 == 8) {//big_brother;} else if (switchVar2 == 16) {//bureaucratic_prostitution;} else if (switchVar2 == 32) {//coordinates_of_social_space;} else if (switchVar2 == 64) {//entrapment;} else if (switchVar2 == 128) {//the_fear;}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;

Page 47: Elevator Programming Code

int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 48: Elevator Programming Code
Page 49: Elevator Programming Code

// 7 April Shift Register Trial A

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 159;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); //switchVar2 = shiftIn(dataPin, clockPin);

if (switchVar1 == 1) {floorcount = 1; // else if (switchVar1 == 2)// {floorcount = 2;}// else if (switchVar1 == 4)// {floorcount = 3;}// else if (switchVar1 == 8)// {floorcount = 4;}

Page 50: Elevator Programming Code

// else if (switchVar1 == 16)// {floorcount = 5;}// else if (switchVar1 == 32)// {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7;}// else if (switchVar1 == 128)// {floorcount = 8;}

// else if (switchVar2 == 1)// {//floorcount = freight move up until released;// }// else if (switchVar2 == 2)// {//floorcount = freight move down until released;// }// else if (switchVar2 == 4)// {//elevator_loveletter;//}// else if (switchVar2 == 8)// {//big_brother;//}// else if (switchVar2 == 16)// {//bureaucratic_prostitution;//}// else if (switchVar2 == 32)// {//coordinates_of_social_space;//}// else if (switchVar2 == 64)// {//entrapment;//} //else if (switchVar2 == 128)// {//the_fear;//}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0;

Page 51: Elevator Programming Code

int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 52: Elevator Programming Code
Page 53: Elevator Programming Code

// 9 April Shift Register Trial A

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 159;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); //switchVar2 = shiftIn(dataPin, clockPin);

if (switchVar1 == 1) {floorcount = 1; // else if (switchVar1 == 2) // {floorcount = 2;} //else if (switchVar1 == 4) // {floorcount = 3;} //else if (switchVar1 == 8) // {floorcount = 4;}

Page 54: Elevator Programming Code

// else if (switchVar1 == 16)// {floorcount = 5;} //else if (switchVar1 == 32) // {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7; //else if (switchVar1 == 128)// {floorcount = 8;}

// else if (switchVar2 > 128) //{//floorcount = freight move up until released; // else if (switchVar2 == 2) //{//floorcount = freight move down until released;// }// else if (switchVar2 == 4)// {//elevator_loveletter;//}// else if (switchVar2 == 8)// {//big_brother;//}// else if (switchVar2 == 16)// {//bureaucratic_prostitution;//}// else if (switchVar2 == 32)// {//coordinates_of_social_space;//}// else if (switchVar2 == 64)// {//entrapment;//} //else if (switchVar2 == 128)// {//the_fear;//}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0;

Page 55: Elevator Programming Code

int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 56: Elevator Programming Code
Page 57: Elevator Programming Code

// 9 April Switch Trial B

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 201;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); switchVar2 = shiftIn(dataPin, clockPin);

// if (switchVar1 == 1) // {floorcount = 1; // else if (switchVar1 == 2) // {floorcount = 2;} //else if (switchVar1 == 4) // {floorcount = 3;} //else if (switchVar1 == 8) // {floorcount = 4;}

Page 58: Elevator Programming Code

// else if (switchVar1 == 16)// {floorcount = 5;} //else if (switchVar1 == 32) // {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7; //else if (switchVar1 == 128)// {floorcount = 8;}

if (switchVar2 == 1) {//floorcount = 10; } else if (switchVar2 == 2) {//floorcount = freight move down until released;// }// else if (switchVar2 == 4)// {//elevator_loveletter;//}// else if (switchVar2 == 8)// {//big_brother;//}// else if (switchVar2 == 16)// {//bureaucratic_prostitution;//}// else if (switchVar2 == 32)// {//coordinates_of_social_space;//}// else if (switchVar2 == 64)// {//entrapment;//} //else if (switchVar2 == 128)// {//the_fear;//}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0;

Page 59: Elevator Programming Code

int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 60: Elevator Programming Code
Page 61: Elevator Programming Code

// April 10 Motor Trial Code

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);//AF_Stepper motor_passenger(200, 2);

void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!");

motor_freight.setSpeed(40); // 30 rpm //motor_passenger.setSpeed(100);

}

void loop() { motor_freight.step(1700, BACKWARD, SINGLE); delay (500); //motor_passenger.step(1, FORWARD, SINGLE); //motor_freight.step(350, FORWARD, SINGLE); //delay(20000); // motor_passenger.step(200, FORWARD, SINGLE); delay(500); }

Page 62: Elevator Programming Code

// April 10 Motor Trial 2

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!");

motor_freight.setSpeed(40); // 30 rpm //motor_passenger.setSpeed(100);

}

void loop() {// motor_freight.step(1700, BACKWARD, SINGLE); //delay (500); motor_passenger.step(700, BACKWARD, SINGLE); //motor_freight.step(350, FORWARD, SINGLE); //delay(20000); //motor_passenger.step(200, FORWARD, SINGLE); delay(1000); }

Page 63: Elevator Programming Code

// Elevator Test_1

//define where your pins areint latchPin = 8;int dataPin = 9;int clockPin = 7;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the dayint floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); if (switchVar1 = 1) {floorcount = 1;} else if (switchVar1 = 2) {floorcount = 2;} else if (switchVar1 = 4) {floorcount = 3;} else if (switchVar1 = 8) {floorcount = 4;} else if (switchVar1 = 16) {floorcount = 5;}

Page 64: Elevator Programming Code

else if (switchVar1 = 32) {floorcount = 6;} else if (switchVar1 = 64) {floorcount = 7;} else if (switchVar1 = 128) {floorcount = 8;}

{digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

Page 65: Elevator Programming Code

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 66: Elevator Programming Code
Page 67: Elevator Programming Code

// Elev Test 2

//define where your pins areint latchPin = 8;int dataPin = 9;int clockPin = 7;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the dayint floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); if (switchVar1 == 1) {floorcount = 1; //else if (switchVar1 = 2)// {floorcount = 2;}// else if (switchVar1 = 4)// {floorcount = 3;}// else if (switchVar1 = 8)// {floorcount = 4;}// else if (switchVar1 = 16)// {floorcount = 5;}

Page 68: Elevator Programming Code

// else if (switchVar1 = 32)// {floorcount = 6;}// else if (switchVar1 = 64)// {floorcount = 7;}// else if (switchVar1 = 128)// {floorcount = 8;}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

Page 69: Elevator Programming Code

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 70: Elevator Programming Code
Page 71: Elevator Programming Code

// Elev Test 3

char passDirection; // hold whether passenger goes up or down//char freightDirection; // hold whether freight goes up or down

int Pass_elevator_Is = 0; // position of elevator at current point in time. this will change with motor movement//int Freight_elevator_Is = 0; // position of elevator at current point in time. this will change with motor movement

void setup(){Serial.begin(9600); //debugging to screen}

/* determine whether motor needs to go forward or backward to bring elevator to pushed call button.

switchvar1 or switchvar2 and elevator_Is from void loop are passed to this function. switchvar1 and switchvar2 go into outside_Button variable. elevator_Is goes into current_Pos variable*/

char elevator_Position( byte outside_Button, byte current_Pos){char direction;

if (outside_Button > current_Pos){direction = "F";}else{direction = "B";}}

void loop{

// button push function here. probably a while loop.

passDirection = elevator_Position(switchVar1, Pass_elevator_Is);freightDirection = elevator_Position(switchVar2, Freight_elevator_Is);

// display value of passDirection and freightDirection. ouput to screenSerial.print("Passenger Direction: ");Serial.println(passDirection);delay(5000);Serial.print("Freight Direction: ");Serial.println(freightDirection);delay(5000);

}

Page 72: Elevator Programming Code
Page 73: Elevator Programming Code

// 15 April Elev Control 4B#include <AFMotor.h>

//AF_Stepper motor_freight(200, 1);

AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is directionless.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start upint stepamount; // variable that holds outside button push

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 159;

// function that returns direction the elevator needs to travel

int elevator_direction(int outside_button, int current_pos){ int direction = 0; //direction elevator travels if (outside_button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down } Serial.print("direction value FROM FUNCTION: "); Serial.println(direction); delay(3000); return direction;}

// end elevator_direction function

// function that returns floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte outside_button){ int floorheight;

Page 74: Elevator Programming Code

switch (outside_button) { case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void setup() {

//start serial

Serial.begin(9600);

// motor_freight.setSpeed(40); // 30 rpm motor_passenger.setSpeed(40); // 30 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop() {

Page 75: Elevator Programming Code

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin);//switchVar2 = shiftIn(dataPin, clockPin);

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // amount of travel necessarySerial.print("Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs to travel we had switchVar1 here and got 1279Serial.print("Pass Direction from void loop: ");Serial.println(passdirection); // debugging

Serial.print("Current position: ");Serial.println(current_pos); //debugging

// stepamount = amountchecker(switchVar1); // amount of travel necessary//Serial.println(stepamount);

if (passdirection == 2){ travel = stepamount - current_pos;} else{ travel = current_pos - stepamount;}

Serial.print("Travel value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

Page 76: Elevator Programming Code

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else { pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 77: Elevator Programming Code

// 15 April Shift Register Trials A

//define where your pins areint latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 72; //default number first comparison first ride of the daybyte switchVar2 = 159;byte switchVar3 = 251;int floorcount = 0;

void setup() { //start serial Serial.begin(9600);

//define pin modes pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

//Pulse the latch pin: //set it to 1 to collect parallel data digitalWrite(latchPin,1); //set it to 1 to collect parallel data, wait delayMicroseconds(20); //set it to 0 to transmit data serially digitalWrite(latchPin,0);

//while the shift register is in serial mode //collect each shift register into a byte //the register attached to the chip comes in first switchVar1 = shiftIn(dataPin, clockPin); //switchVar2 = shiftIn(dataPin, clockPin); switchVar3 = shiftIn(dataPin, clockPin);

//if (switchVar1 == 1) //{floorcount = 1; // else if (switchVar1 == 2) // {floorcount = 2;} //else if (switchVar1 == 4) // {floorcount = 3;}

Page 78: Elevator Programming Code

//else if (switchVar1 == 8) // {floorcount = 4;}// else if (switchVar1 == 16)// {floorcount = 5;} //else if (switchVar1 == 32) // {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7; //else if (switchVar1 == 128)// {floorcount = 8;}

// else if (switchVar2 > 128) //{//floorcount = freight move up until released; // else if (switchVar2 == 2) //{//floorcount = freight move down until released;// }// else if (switchVar2 == 4)// {//elevator_loveletter;//}// else if (switchVar2 == 8)// {//big_brother;//}// else if (switchVar2 == 16)// {//bureaucratic_prostitution;//}// else if (switchVar2 == 32)// {//coordinates_of_social_space;//}// else if (switchVar2 == 64)// {//entrapment;//} //else if (switchVar2 == 128)// {//the_fear;//} if (switchVar3 > 0) {//floorcount = 1; // else if (switchVar1 == 2) // {floorcount = 2;} //else if (switchVar1 == 4) // {floorcount = 3;} //else if (switchVar1 == 8) // {floorcount = 4;}// else if (switchVar1 == 16)// {floorcount = 5;} //else if (switchVar1 == 32) // {floorcount = 6;}// else if (switchVar1 == 64)// {floorcount = 7; //else if (switchVar1 == 128)// {floorcount = 8;}

Page 79: Elevator Programming Code

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i; int temp = 0; int pinState; byte myDataIn = 0;

pinMode(myClockPin, OUTPUT); pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts down for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); delayMicroseconds(0.2); temp = digitalRead(myDataPin); if (temp) { pinState = 1; //set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); } else { //turn it off -- only necessary for debuging //print statement since myDataIn starts as 0 pinState = 0; }

//Debuging print statements // Serial.print(pinState); //Serial.print("Marnie"); //Serial.println (dataIn, BIN);

Page 80: Elevator Programming Code

digitalWrite(myClockPin, 1);

} //debuging print statements whitespace //Serial.println(); //Serial.println(myDataIn, BIN); return myDataIn;}

Page 81: Elevator Programming Code

// 15 April Elev Code D

#include <AFMotor.h>

//AF_Stepper motor_freight(200, 1);

AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is directionless.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start upint stepamount; // variable that holds outside button push

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 159;byte switchVar3 = 251,

// function that returns direction the elevator needs to travel

int elevator_direction(int outside_button, int current_pos){ int direction = 0; //direction elevator travels if (outside_button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down } Serial.print("direction value FROM FUNCTION: "); Serial.println(direction); delay(3000); return direction;}

// end elevator_direction function

// function that returns floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte outside_button)

Page 82: Elevator Programming Code

{ int floorheight; switch (outside_button) { case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void setup() {

//start serial

Serial.begin(9600);

// motor_freight.setSpeed(40); // 30 rpm motor_passenger.setSpeed(40); // 30 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop() {

Page 83: Elevator Programming Code

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin);switchVar2 = shiftIn(dataPin, clockPin);switchVar3 = shiftIn(dataPin, clockPin);

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // amount of travel necessarySerial.print("Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs to travel we had switchVar1 here and got 1279Serial.print("Pass Direction from void loop: ");Serial.println(passdirection); // debugging

Serial.print("Current position: ");Serial.println(current_pos); //debugging

// stepamount = amountchecker(switchVar1); // amount of travel necessary//Serial.println(stepamount);

if (passdirection == 2){ travel = stepamount - current_pos;} else{ travel = current_pos - stepamount;}

Serial.print("Travel value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

Page 84: Elevator Programming Code

}

/// shift register 2

else if (switchVar2 ! = 0){stepamount = amountchecker(switchVar1); // amount of travel necessarySerial.print("Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs to travel we had switchVar1 here and got 1279Serial.print("Pass Direction from void loop: ");Serial.println(passdirection); // debugging

Serial.print("Current position: ");Serial.println(current_pos); //debugging

// stepamount = amountchecker(switchVar1); // amount of travel necessary//Serial.println(stepamount);

if (passdirection == 2){ travel = stepamount - current_pos;} else{ travel = current_pos - stepamount;}

Serial.print("Travel value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

////shift register 3

else if (switchVar 3 == 1) {//elevator_love letters //else if (switchVar3 == 2) //{// // } //else if (switchVar2 == 4) // {//elevator_loveletter; //move both freight and passenger elevator to the 6 floor//}

Page 85: Elevator Programming Code

// else if (switchVar2 == 8) //{//big_brother;//} //else if (switchVar2 == 16) //{//bureaucratic_prostitution;//}// else if (switchVar3 == 32)//{//coordinates_of_social_space; //} //else if (switchVar2 == 64) //{//entrapment; //} //else if (switchVar2 == 128) //{//the_fear; //} digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);} }

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what

Page 86: Elevator Programming Code

myDataIn = myDataIn | (1 << i); }else { pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 87: Elevator Programming Code

// 16 April Elev Code A

#include <AFMotor.h>

//AF_Stepper motor_freight(200, 2);

AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is direction independent.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start upint stepamount; // variable that holds value assigned to floor where the outside button is pushed

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 159;byte switchVar3 = 251;

// function that returns direction the elevator needs to travel

int elevator_direction(int outside_button, int current_pos){ int direction = 0; //direction elevator travels

if (outside_button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down } Serial.print("direction value FROM FUNCTION: "); Serial.println(direction); delay(3000); return direction;}

// end elevator_direction function

// function that returns floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte outside_button)

Page 88: Elevator Programming Code

{ int floorheight;

switch (outside_button) { case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void setup(){

//start serial

Serial.begin(9600);

// motor_freight.setSpeed(40); // 30 rpm motor_passenger.setSpeed(40); // 30 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

Page 89: Elevator Programming Code

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin);switchVar2 = shiftIn(dataPin, clockPin);switchVar3 = shiftIn(dataPin, clockPin);

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // amount of travel necessarySerial.print("Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs to travel we had switchVar1 here and got 1279Serial.print("Pass Direction from void loop: ");Serial.println(passdirection); // debugging

Serial.print("Current position: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos;} else{ travel = current_pos - stepamount;}

Serial.print("Travel value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

Page 90: Elevator Programming Code

/// shift register 2

if (switchVar2 != 0){stepamount = amountchecker(switchVar1); // amount of travel necessarySerial.print("Inside button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs to travel we had switchVar1 here and got 1279Serial.print("Inside button Pass Direction from void loop: ");Serial.println(passdirection); // debugging

Serial.print("Current position: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos;} else{ travel = current_pos - stepamount;}

Serial.print("Travel value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

////shift register 3

if (switchVar3 == 1){//elevator_love letters

//else if (switchVar3 == 2)//{//// }//else if (switchVar2 == 4)// {//elevator_loveletter;//move both freight and passenger elevator to the 6 floor//}// else if (switchVar2 == 8) //{//big_brother;//}//else if (switchVar2 == 16) //{//bureaucratic_prostitution;

Page 91: Elevator Programming Code

//}// else if (switchVar3 == 32)//{//coordinates_of_social_space;//}//else if (switchVar2 == 64)//{//entrapment;//} //else if (switchVar2 == 128)//{//the_fear;//}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);} }

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0;

Page 92: Elevator Programming Code

}

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 93: Elevator Programming Code

// 16 April Elev Code B

#include <AFMotor.h>

//AF_Stepper motor_freight(200, 1);

AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is direction independent.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start upint stepamount; // variable that holds value assigned to floor where the outside button is pushed

//Define variables to hold the data //for shift register.//starting with a non-zero numbers can help//troubleshootbyte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 251;

// function that returns direction the elevator needs to travel

int elevator_direction(int outside_button, int current_pos){ int direction = 0; //direction elevator travels

if (outside_button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down } Serial.print("direction value FROM FUNCTION: "); Serial.println(direction); delay(3000); return direction;}

// end elevator_direction function

// function that returns floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte outside_button)

Page 94: Elevator Programming Code

{ int floorheight;

switch (outside_button) { case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void setup(){

//start serial

Serial.begin(9600);

// motor_freight.setSpeed(40); // 30 rpm motor_passenger.setSpeed(40); // 30 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

Page 95: Elevator Programming Code

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin);switchVar2 = shiftIn(dataPin, clockPin);switchVar3 = shiftIn(dataPin, clockPin);

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // amount of travel necessarySerial.print("Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs to travel we had switchVar1 here and got 1279Serial.print("Pass Direction from void loop: ");Serial.println(passdirection); // debugging

Serial.print("Current position: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos;} else{ travel = current_pos - stepamount;}

Serial.print("Travel value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

Page 96: Elevator Programming Code

/// shift register 2

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // amount of travel necessarySerial.print("Inside button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs to travel we had switchVar1 here and got 1279Serial.print("Inside button Pass Direction from void loop: ");Serial.println(passdirection); // debugging

Serial.print("Current position: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos;} else{ travel = current_pos - stepamount;}

Serial.print("Travel value from inside button: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

////shift register 3

if (switchVar3 == 1){//elevator_love letters

//else if (switchVar3 == 2)//{//// }//else if (switchVar2 == 4)// {//elevator_loveletter;//move both freight and passenger elevator to the 6 floor//}// else if (switchVar2 == 8) //{//big_brother;//}//else if (switchVar2 == 16) //{//bureaucratic_prostitution;

Page 97: Elevator Programming Code

//}// else if (switchVar3 == 32)//{//coordinates_of_social_space;//}//else if (switchVar2 == 64)//{//entrapment;//} //else if (switchVar2 == 128)//{//the_fear;//}

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);} }

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0;

Page 98: Elevator Programming Code

}

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 99: Elevator Programming Code

// 17 April Elev Code A

#include <AFMotor.h>

//AF_Stepper motor_freight(200, 1);

AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is direction independent.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 1000; // current position of elevator. set to 1000 ground floor at start up.int stepamount; // variable that holds value assigned to floor where a button is pushed.

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 251;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){ int direction = 0; //direction elevator travels

if (button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down }

delay(3000); return direction;}

// end elevator_direction function

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button){ int floorheight;

Page 100: Elevator Programming Code

switch (button) { case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void elevator_love letters{}

void elevator_loveletter(){}

void big_brother(){}

void bureaucratic_prostitution{}

void coordinates_of_social_space(){}

void the_fear(){

Page 101: Elevator Programming Code

}

void entrapment(){}

void setup(){

//start serial

Serial.begin(9600);

// motor_freight.setSpeed(40); // 30 rpm motor_passenger.setSpeed(40); // 30 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedSerial.print("Outside Button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

Page 102: Elevator Programming Code

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("Outside Button Pass Direction: ");Serial.println(passdirection); // debugging

Serial.print("Current position of elevator: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Outside Button Travel Value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedSerial.print("Inside button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("Inside button Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Inside Button Travel Value: "); //debuggingSerial.println(travel); //debugging

Page 103: Elevator Programming Code

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

////shift register 3 Special Features

//if (switchVar3 == 1)// {//elevator_love letters

//else if (switchVar3 == 2)//{//// }//else if (switchVar2 == 4)// {//elevator_loveletter;//move both freight and passenger elevator to the 6 floor//}// else if (switchVar2 == 8) //{//big_brother;//}//else if (switchVar2 == 16) //{//bureaucratic_prostitution;//}// else if (switchVar3 == 32)//{//coordinates_of_social_space;//}//else if (switchVar2 == 64)//{//entrapment;//} //else if (switchVar2 == 128)//{//the_fear;//}//}

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedSerial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2)

Page 104: Elevator Programming Code

{ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

switch (switchVar3) { case 1: elevator_love letters(); break; case 2:

break; case 4: elevator_loveletter(); break; case 8: big_brother(); break; case 16: bureaucratic_prostitution(); break; case 32: coordinates_of_social_space(); break; case 64: entrapment(); break; case 128: the_fear(); break; }

//motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

Page 105: Elevator Programming Code

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 106: Elevator Programming Code
Page 107: Elevator Programming Code

// 17 April Elev Code B

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is direction independent.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 1000; // current position of elevator. set to 1000 ground floor at start up.int stepamount; // variable that holds value assigned to floor where a button is pushed.

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 251;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){ int direction = 0; //direction elevator travels

if (button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down }

delay(3000); return direction;}

// end elevator_direction function

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button){ int floorheight;

switch (button)

Page 108: Elevator Programming Code

{ case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){}

void the_fear(){}

Page 109: Elevator Programming Code

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

Page 110: Elevator Programming Code

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedSerial.print("Outside Button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("Outside Button Pass Direction: ");Serial.println(passdirection); // debugging

Serial.print("Current position of elevator: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Outside Button Travel Value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedSerial.print("Inside button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("Inside button Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debugging

Page 111: Elevator Programming Code

Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Inside Button Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

////shift register 3 Special Features

//if (switchVar3 == 1)// {//elevator_love letters

//else if (switchVar3 == 2)//{//// }//else if (switchVar2 == 4)// {//elevator_loveletter;//move both freight and passenger elevator to the 6 floor//}// else if (switchVar2 == 8) //{//big_brother;//}//else if (switchVar2 == 16) //{//bureaucratic_prostitution;//}// else if (switchVar3 == 32)//{//coordinates_of_social_space;//}//else if (switchVar2 == 64)//{//entrapment;//} //else if (switchVar2 == 128)//{//the_fear;//}//}

if (switchVar3 != 0){

Page 112: Elevator Programming Code

stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedSerial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

switch (switchVar3) { case 1: elevator_love_letters(); break; case 2:

break; case 4: gateway_to_the_soul(); break; case 8: big_brother(); break; case 16: bureaucratic_prostitution(); break; case 32: coordinates_of_social_space(); break; case 64: the_end_of_the_world(); break; case 128: the_fear(); break; }

//motor_passenger.step(travel, passdirection, SINGLE);

Page 113: Elevator Programming Code

current_pos = stepamount;

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

Page 114: Elevator Programming Code

}

return myDataIn;

}

Page 115: Elevator Programming Code

// 17 April Elev Code C#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is direction independent.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 650; // current position of elevator. set to 1000 ground floor at start up.int stepamount; // variable that holds value assigned to floor where a button is pushed.

int freight_pos = 1000; // current position of freight elevatorint f_speed = 10; // speed of freight elevator

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 251;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){ int direction = 0; //direction elevator travels

if (button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down }

delay(3000); return direction;}

// end elevator_direction function

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button)

Page 116: Elevator Programming Code

{ int floorheight;

switch (button) { case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){}

Page 117: Elevator Programming Code

void the_fear(){}

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially

Page 118: Elevator Programming Code

digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedSerial.print("Outside Button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("Outside Button Pass Direction: ");Serial.println(passdirection); // debugging

Serial.print("Current position of elevator: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Outside Button Travel Value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedSerial.print("Inside button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevator

Page 119: Elevator Programming Code

Serial.print("Inside button Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Inside Button Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

////shift register 3 Special Features

//if (switchVar3 == 1)// {//elevator_love letters

//else if (switchVar3 == 2)//{//// }//else if (switchVar2 == 4)// {//elevator_loveletter;//move both freight and passenger elevator to the 6 floor//}// else if (switchVar2 == 8) //{//big_brother;//}//else if (switchVar2 == 16) //{//bureaucratic_prostitution;//}// else if (switchVar3 == 32)//{//coordinates_of_social_space;//}//else if (switchVar2 == 64)//{//entrapment;//} //else if (switchVar2 == 128)//{//the_fear;//}

Page 120: Elevator Programming Code

//}

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedSerial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

switch (switchVar3) { case 1: // the Freight Up Button motor_freight.step(f_speed, BACKWARD, SINGLE); freight_pos = freight_pos + f_speed; break; case 2: // motor_freight.step(f_speed, FORWARD, SINGLE); freight_pos = freight_pos - f_speed; break;

break; case 4: stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedSerial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Page 121: Elevator Programming Code

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(700, FORWARD, SINGLE);current_pos = current_pos - 700;delay(2000);break;

case 8: stepamount = 3100;

Serial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2)

Page 122: Elevator Programming Code

{ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

Serial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - freight_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = freight_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_freight.step(travel, passdirection, SINGLE);freight_pos = stepamount;break;

case 16: bureaucratic_prostitution(); break;

Page 123: Elevator Programming Code

case 32: coordinates_of_social_space(); break; case 64: the_end_of_the_world(); break; case 128: stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressed Serial.print("SwitchVar3 Step Amount value: "); //debugging Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevator Serial.print("SwitchVar3 Pass Direction: "); //debugging Serial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debugging Serial.println(current_pos); //debugging

if (passdirection == 2) { travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2 } else { travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1 }

Serial.print("SwitchVar3 Travel Value: "); //debugging Serial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE); current_pos = stepamount;

for (int hover = 0; hover <= 10; hover ++) { motor_passenger.step(10, FORWARD, SINGLE); delay(500); motor_passenger.step(10, BACKWARD, SINGLE); delay(500); }

}

//motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1); //debugging

Page 124: Elevator Programming Code

delay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

Page 125: Elevator Programming Code

return myDataIn;

}

Page 126: Elevator Programming Code
Page 127: Elevator Programming Code

// 17 April Elev Code D

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int travel =0; //amount elevator will move. is direction independent.int passdirection = 0; // direction elevator will travel. will be 1 is Forward or 2 is Backward.int current_pos = 650; // current position of elevator. set to 1000 ground floor at start up.int stepamount; // variable that holds value assigned to floor where a button is pushed.

int freight_pos = 1000; // current position of freight elevatorint f_speed = 10; // speed of freight elevator

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 251;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){ int direction = 0; //direction elevator travels

if (button > current_pos) { direction = 2; // this is up } else { direction = 1; // this is down }

delay(3000); return direction;}

// end elevator_direction function

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

Page 128: Elevator Programming Code

int amountchecker(byte button){ int floorheight;

switch (button) { case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break; } return floorheight;}

// end function amountchecker

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){

Page 129: Elevator Programming Code

}

void the_fear(){}

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

Page 130: Elevator Programming Code

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedSerial.print("Outside Button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("Outside Button Pass Direction: ");Serial.println(passdirection); // debugging

Serial.print("Current position of elevator: ");Serial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Outside Button Travel Value: ");Serial.println(travel);

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1);delay(1000);digitalWrite (ledPin,0);

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedSerial.print("Inside button Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

Page 131: Elevator Programming Code

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("Inside button Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("Inside Button Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

////shift register 3 Special Features

//if (switchVar3 == 1)// {//elevator_love letters

//else if (switchVar3 == 2)//{//// }//else if (switchVar2 == 4)// {//elevator_loveletter;//move both freight and passenger elevator to the 6 floor//}// else if (switchVar2 == 8) //{//big_brother;//}//else if (switchVar2 == 16) //{//bureaucratic_prostitution;//}// else if (switchVar3 == 32)//{//coordinates_of_social_space;//}//else if (switchVar2 == 64)//{//entrapment;//} //else if (switchVar2 == 128)//{//the_fear;

Page 132: Elevator Programming Code

//}//}

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedSerial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

switch (switchVar3) { case 1: // the Freight Up Button motor_freight.step(f_speed, BACKWARD, SINGLE); freight_pos = freight_pos + f_speed; break; case 2: // motor_freight.step(f_speed, FORWARD, SINGLE); freight_pos = freight_pos - f_speed; break;

break; case 4: stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedSerial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Page 133: Elevator Programming Code

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(700, FORWARD, SINGLE);current_pos = current_pos - 700;delay(2000);break;

case 8: stepamount = 3100;

Serial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

Page 134: Elevator Programming Code

if (passdirection == 2){ travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

Serial.print("SwitchVar3 Step Amount value: "); //debuggingSerial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of elevatorSerial.print("SwitchVar3 Pass Direction: "); //debuggingSerial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debuggingSerial.println(current_pos); //debugging

if (passdirection == 2){ travel = stepamount - freight_pos; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = freight_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

Serial.print("SwitchVar3 Travel Value: "); //debuggingSerial.println(travel); //debugging

delay(500);

motor_freight.step(travel, passdirection, SINGLE);freight_pos = stepamount;break;

case 16: bureaucratic_prostitution();

Page 135: Elevator Programming Code

break; case 32: coordinates_of_social_space(); break; case 64: the_end_of_the_world(); break; case 128: stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressed Serial.print("SwitchVar3 Step Amount value: "); //debugging Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevator Serial.print("SwitchVar3 Pass Direction: "); //debugging Serial.println(passdirection); // debugging

Serial.print("Current position of elevator: "); //debugging Serial.println(current_pos); //debugging

if (passdirection == 2) { travel = stepamount - current_pos; // calculate number of steps elevator needs to travel if direction equals 2 } else { travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if direction equals 1 }

Serial.print("SwitchVar3 Travel Value: "); //debugging Serial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE); current_pos = stepamount;

for (int hover = 0; hover <= 10; hover ++) { motor_passenger.step(10, FORWARD, SINGLE); delay(500); motor_passenger.step(10, BACKWARD, SINGLE); delay(500); }

}

//motor_passenger.step(travel, passdirection, SINGLE);current_pos = stepamount;

Page 136: Elevator Programming Code

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

digitalWrite(ledPin,1); //debuggingdelay(1000); //debuggingdigitalWrite (ledPin,0); //debugging

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

Page 137: Elevator Programming Code

return myDataIn;

}

Page 138: Elevator Programming Code
Page 139: Elevator Programming Code

// 18 April Elev Code A

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int passtravel =0; //amount pass elevator will move. is direction independent.int freighttravel = 0; // amount freight elevator will move.int passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or 2 is Backward.int freightdirection= 0; // direction freight elevator will travel.int current_pos = 650; // current position of elevator. set to 1000 ground floor at start up.int stepamount; // variable that holds value assigned to floor where a button is pushed.

int freight_pos = 1000; // current position of freight elevatorint f_speed = 10; // speed of freight elevator

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 0;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){int direction = 0; //direction elevator travels

if (button > current_pos){ direction = 2; // this is up}else{ direction = 1; // this is down}

return direction;}

// end elevator_direction function

// Function that returns travel distance of elevator

Page 140: Elevator Programming Code

int travel_amount(int stepamount, int position, int tdirection){ int travel = 0;

if (tdirection == 2){ travel = stepamount - position; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = position - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

return travel;}

// end function travel_amount

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button){int floorheight;

switch (button){ case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break;}return floorheight;}

Page 141: Elevator Programming Code

// end function amountchecker

// start direction function

//int direction(

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){}

void the_fear(){}

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

Page 142: Elevator Programming Code

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

Page 143: Elevator Programming Code

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

switch (switchVar3){case 1: // the Freight Up Buttonmotor_freight.step(f_speed, BACKWARD, SINGLE);freight_pos = freight_pos + f_speed;break;

case 2: //motor_freight.step(f_speed, FORWARD, SINGLE);freight_pos = freight_pos - f_speed;break;

case 4:stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(700, FORWARD, SINGLE);current_pos = current_pos - 700;delay(2000);break;

case 8:stepamount = 3100;passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

Page 144: Elevator Programming Code

freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of elevatorfreighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine travel amount;

motor_freight.step(freighttravel, freightdirection, SINGLE);freight_pos = stepamount;break;

case 16:bureaucratic_prostitution();break;case 32:coordinates_of_social_space();break;case 64:the_end_of_the_world();break;

case 128:stepamount = 3450; // 8th floorpassdirection = elevator_direction(stepamount, current_pos);//determine travel direction of passenger elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amountfreightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of freight elevatorfreighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight travel amount

for (int go =0; go <= 3450; go++){if (current_pos < passtravel){ motor_passenger.step(1, passdirection, SINGLE); current_pos = current_pos + 1; // i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}if (freight_pos < freighttravel){ motor_freight.step(1, freightdirection, SINGLE); freight_pos = freight_pos + 1; //i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}}

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;

Page 145: Elevator Programming Code

pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 146: Elevator Programming Code

// 18 April Elev Code A1

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int passtravel =0; //amount pass elevator will move. is direction independent.int freighttravel = 0; // amount freight elevator will move.int totalpasstravel = 0; // current_pos + passtravel for moving passenger elevator to desired floorint totalfreighttravel = 0; // freight_pos + freighttravel for moving freight elevator to a desired floorint passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or 2 is Backward.int freightdirection= 0; // direction freight elevator will travel.int current_pos = 650; // current position of elevator. set to 1000 ground floor at start up.int freight_pos = 650; // current position of freight elevatorint stepamount; // variable that holds value assigned to floor where a button is pushed.int f_speed = 10; // speed of freight elevator

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 0;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){int elev_direction = 0; //direction elevator travels

if (button > current_pos){ elev_direction = 2; // this is up}else{ elev_direction = 1; // this is down}

return elev_direction;}

// end elevator_direction function

// Function that returns travel distance of elevator

Page 147: Elevator Programming Code

int travel_amount(int stepamount, int position, int travel_direction){ int travel = 0;

if (travel_direction == 2){ travel = stepamount - position; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = position - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

return travel;}

// end function travel_amount

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button){int floorheight;

switch (button){ case 1://floor 1 floorheight = 988; break; case 2://floor 2 floorheight = 1310; break; case 4://floor 3 floorheight = 1630; break; case 8://floor 4 floorheight = 1940; break; case 16://floor 5 floorheight = 2270; break; case 32://floor 6 floorheight = 2600; break; case 64://floor 7 floorheight = 3075; break; case 128://floor 8 floorheight = 3400; break;}return floorheight;}

Page 148: Elevator Programming Code

// end function amountchecker

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){}

void the_fear(){}

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

Page 149: Elevator Programming Code

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

Page 150: Elevator Programming Code

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

switch (switchVar3){case 1: // the Freight Up Buttonmotor_freight.step(f_speed, BACKWARD, SINGLE);freight_pos = freight_pos + f_speed;break;

case 2: //motor_freight.step(f_speed, FORWARD, SINGLE);freight_pos = freight_pos - f_speed;break;

case 4:stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(700, FORWARD, SINGLE);current_pos = current_pos - 700;delay(2000);break;

case 8:/*

THIS IS OLD CODE.

stepamount = 3100;passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of elevator

Page 151: Elevator Programming Code

freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine travel amount;

motor_freight.step(freighttravel, freightdirection, SINGLE);freight_pos = stepamount; */

/* This is new code */

stepamount = 3400; // 8th floorpassdirection = elevator_direction(stepamount, current_pos);//determine travel direction of passenger elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amounttotalpasstravel = current_pos + passtravel;

freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of freight elevatorfreighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight travel amounttotalfreighttravel = freight_pos + freighttravel;

for (int go =0; go <= 3450; go++){if (current_pos < totalpasstravel) //pass travel and freighttravel do not work here.{motor_passenger.step(1, passdirection, SINGLE);current_pos = current_pos + 1; // i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}if (freight_pos < totalfreighttravel){motor_freight.step(1, freightdirection, SINGLE);freight_pos = freight_pos + 1; //i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}}

Serial.print("Current Position of Passenger: ");Serial.println(current_pos);Serial.print("Current Position of Freight: ");Serial.println(freight_pos);delay(5000);

break;

case 16:bureaucratic_prostitution();break;case 32:coordinates_of_social_space();break;case 64:the_end_of_the_world();break;

case 128:stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);

Page 152: Elevator Programming Code

current_pos = stepamount;

for (int hover = 0; hover <= 10; hover ++){motor_passenger.step(10, FORWARD, SINGLE);delay(500);motor_passenger.step(10, BACKWARD, SINGLE);delay(500);}

current_pos = stepamount;Serial.print("Current Position of Passenger: ");Serial.println(current_pos);Serial.print("Current Position of Freight: ");Serial.println(freight_pos);delay(5000);break;} // end switch (case) statement

//current_pos = stepamount;

} // end switchvar3 if statement} // end main loop

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) {

Page 153: Elevator Programming Code

pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 154: Elevator Programming Code
Page 155: Elevator Programming Code

// 18 Elev Code B

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int passtravel =0; //amount pass elevator will move. is direction independent.int freighttravel = 0; // amount freight elevator will move.int passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or 2 is Backward.int freightdirection= 0; // direction freight elevator will travel.int current_pos = 650; // current position of elevator. set to 650 basement floor at start up.int stepamount; // variable that holds value assigned to floor where a button is pushed.

int freight_pos = 1000; // current position of freight elevatorint f_speed = 10; // speed of freight elevator

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 0;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){int direction = 0; //direction elevator travels

if (button > current_pos){ direction = 2; // this is up}else{ direction = 1; // this is down}

return direction;}

// end elevator_direction function

// Function that returns travel distance of elevator

Page 156: Elevator Programming Code

int travel_amount(int stepamount, int position, int tdirection){ int travel = 0;

if (tdirection == 2){ travel = stepamount - position; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = position - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

return travel;}

// end function travel_amount

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button){int floorheight;

switch (button){ case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3150; // this no. can change it's a safety precaution break;}return floorheight;}

Page 157: Elevator Programming Code

// end function amountchecker

// start direction function

//int direction(

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){}

void the_fear(){}

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

Page 158: Elevator Programming Code

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

Page 159: Elevator Programming Code

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

switch (switchVar3){case 1: // the Freight Up Buttonmotor_freight.step(f_speed, BACKWARD, SINGLE);freight_pos = freight_pos + f_speed;break;

case 2: //motor_freight.step(f_speed, FORWARD, SINGLE);freight_pos = freight_pos - f_speed;break;

case 4:stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(700, FORWARD, SINGLE);current_pos = current_pos - 700;delay(2000);break;

case 8:stepamount = 3100; // 8th floorpassdirection = elevator_direction(stepamount, current_pos);//determine travel direction of passenger elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amountfreightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of freight elevatorfreighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight travel amount

for (int go =0; go <= 3450; go++)

Page 160: Elevator Programming Code

{if (current_pos < stepamount){ motor_passenger.step(1, passdirection, SINGLE); current_pos = current_pos + 1; // i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}if (freight_pos < stepamount){ motor_freight.step(1, freightdirection, SINGLE); freight_pos = freight_pos + 1; //i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}}break;

case 16:bureaucratic_prostitution();break;case 32:coordinates_of_social_space();break;case 64:the_end_of_the_world();break;

case 128:// goes to high. need to change that number//stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

for (int hover = 0; hover <= 10; hover ++){motor_passenger.step(10, FORWARD, SINGLE);delay(500);motor_passenger.step(10, BACKWARD, SINGLE);delay(500);}

current_pos = stepamount;}}}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

Page 161: Elevator Programming Code

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 162: Elevator Programming Code
Page 163: Elevator Programming Code

// 18 April Elev Code C

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int passtravel =0; //amount pass elevator will move. is direction independent.int freighttravel = 0; // amount freight elevator will move.int totalpasstravel = 0; // current_pos + passtravel for moving passenger elevator to desired floorint totalfreighttravel = 0; // freight_pos + freighttravel for moving freight elevator to a desired floorint passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or 2 is Backward.int freightdirection= 0; // direction freight elevator will travel.int current_pos = 650; // current position of elevator. set to 1000 ground floor at start up.int freight_pos = 650; // current position of freight elevatorint stepamount; // variable that holds value assigned to floor where a button is pushed.int f_speed = 10; // speed of freight elevator

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 0;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){int elev_direction = 0; //direction elevator travels

if (button > current_pos){ elev_direction = 2; // this is up}else{ elev_direction = 1; // this is down}

return elev_direction;}

// end elevator_direction function

// Function that returns travel distance of elevator

Page 164: Elevator Programming Code

int travel_amount(int stepamount, int position, int travel_direction){ int travel = 0;

if (travel_direction == 2){ travel = stepamount - position; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = position - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

return travel;}

// end function travel_amount

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button){int floorheight;

switch (button){ case 1: floorheight = 1000; break; case 2: floorheight = 1350; break; case 4: floorheight = 1700; break; case 8: floorheight = 2050; break; case 16: floorheight = 2400; break; case 32: floorheight = 2750; break; case 64: floorheight = 3100; break; case 128: floorheight = 3450; break;}return floorheight;}

Page 165: Elevator Programming Code

// end function amountchecker

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){}

void the_fear(){}

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

Page 166: Elevator Programming Code

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

Page 167: Elevator Programming Code

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

switch (switchVar3){case 1: // the Freight Up Buttonmotor_freight.step(f_speed, BACKWARD, SINGLE);freight_pos = freight_pos + f_speed;break;

case 2: //motor_freight.step(f_speed, FORWARD, SINGLE);freight_pos = freight_pos - f_speed;break;

case 4:stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);current_pos = current_pos + 175;delay(2000);

motor_passenger.step(700, FORWARD, SINGLE);current_pos = current_pos - 700;delay(2000);break;

case 8:/*

THIS IS OLD CODE.

stepamount = 3100;passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of elevator

Page 168: Elevator Programming Code

freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine travel amount;

motor_freight.step(freighttravel, freightdirection, SINGLE);freight_pos = stepamount; */

/* This is new code */

stepamount = 3100; // 8th floorpassdirection = elevator_direction(stepamount, current_pos);//determine travel direction of passenger elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amounttotalpasstravel = current_pos + passtravel;

freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of freight elevatorfreighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight travel amounttotalfreighttravel = freight_pos + freighttravel;

for (int go =0; go <= 3450; go++){if (current_pos < totalpasstravel) //pass travel and freighttravel do not work here.{motor_passenger.step(1, passdirection, SINGLE);current_pos = current_pos + 1; // i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}if (freight_pos < totalfreighttravel){motor_freight.step(1, freightdirection, SINGLE);freight_pos = freight_pos + 1; //i think the problem is right here. it might work with going to floor 8, but maybe noit with other floors.}}

Serial.print("Current Position of Passenger: ");Serial.println(current_pos);Serial.print("Current Position of Freight: ");Serial.println(freight_pos);delay(5000);

break;

case 16:bureaucratic_prostitution();break;case 32:coordinates_of_social_space();break;case 64:the_end_of_the_world();break;

case 128:stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);

Page 169: Elevator Programming Code

current_pos = stepamount;

for (int hover = 0; hover <= 10; hover ++){motor_passenger.step(10, FORWARD, SINGLE);delay(500);motor_passenger.step(10, BACKWARD, SINGLE);delay(500);}

current_pos = stepamount;Serial.print("Current Position of Passenger: ");Serial.println(current_pos);Serial.print("Current Position of Freight: ");Serial.println(freight_pos);delay(5000);break;} // end switch (case) statement

//current_pos = stepamount;

} // end switchvar3 if statement} // end main loop

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) {

Page 170: Elevator Programming Code

pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}

Page 171: Elevator Programming Code

// April 19 Elevator Code

#include <AFMotor.h>

AF_Stepper motor_freight(200, 2);AF_Stepper motor_passenger(200, 1);

//define where your Shift Register pins are

int latchPin = 2;int dataPin = 9;int clockPin = 10;int ledPin = 13;

int passtravel =0; //amount pass elevator will move. is direction independent.int freighttravel = 0; // amount freight elevator will move.int totalpasstravel = 0; // current_pos + passtravel for moving passenger elevator to desired floorint totalfreighttravel = 0; // freight_pos + freighttravel for moving freight elevator to a desired floorint passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or 2 is Backward.int freightdirection= 0; // direction freight elevator will travel.int current_pos = 650; // current position of elevator. set to 1000 ground floor at start up.int freight_pos = 650; // current position of freight elevatorint stepamount; // variable that holds value assigned to floor where a button is pushed.int f_speed = 10; // speed of freight elevator

//Define variables to hold the data for shift registers. Starting with a non-zero numbers can help troubleshoot

byte switchVar1 = 0; //default number first comparison first ride of the daybyte switchVar2 = 0;byte switchVar3 = 0;

// Function that returns direction the elevator needs to travel.

int elevator_direction(int button, int current_pos){int elev_direction = 0; //direction elevator travels

if (button > current_pos){ elev_direction = 2; // this is up}else{ elev_direction = 1; // this is down}

return elev_direction;}

// end elevator_direction function

// Function that returns travel distance of elevator

Page 172: Elevator Programming Code

int travel_amount(int stepamount, int position, int travel_direction){ int travel = 0;

if (travel_direction == 2){ travel = stepamount - position; // calculate number of steps elevator needs to travel if direction equals 2} else{ travel = position - stepamount; // calculate number of steps elevator needs to travel if direction equals 1}

return travel;}

// end function travel_amount

// Function amountchecker. Returns preset floorheight value// at 3/8th scale this means 4.5 inches is one floor which is 350 steps per floor

int amountchecker(byte button){int floorheight;

switch (button){ case 1://floor 1 floorheight = 988; break; case 2://floor 2 floorheight = 1320; break; case 4://floor 3 floorheight = 1660; break; case 8://floor 4 floorheight = 1999; break; case 16://floor 5 floorheight = 2350; break; case 32://floor 6 floorheight = 2670; break; case 64://floor 7 floorheight = 3000; break; case 128://floor 8 floorheight = 3300; break;}return floorheight;}

Page 173: Elevator Programming Code

// end function amountchecker

void elevator_love_letters(){}

void gateway_to_the_soul(){}

void big_brother(){}

void bureaucratic_prostitution(){}

void coordinates_of_social_space(){}

void the_fear(){}

void make_nice(){}

void we_have_a_situation_here(){}

void the_end_of_the_world (){}

void pages_from_a_diary(){}

void setup(){

//start serial

Serial.begin(9600);

motor_freight.setSpeed(40); // 40 rpm motor_passenger.setSpeed(40); // 40 rpm

Page 174: Elevator Programming Code

//define pin modes

pinMode(latchPin, OUTPUT);pinMode(clockPin, OUTPUT); pinMode(dataPin, INPUT);pinMode(ledPin, OUTPUT);

}

void loop(){

//Pulse the latch pin://set it to 1 to collect parallel datadigitalWrite(latchPin,1);//set it to 1 to collect parallel data, wait

delayMicroseconds(20);

//set it to 0 to transmit data serially digitalWrite(latchPin,0);//while the shift register is in serial mode//collect each shift register into a byte//the register attached to the chip comes in first

switchVar1 = shiftIn(dataPin, clockPin); // outside buttonsswitchVar2 = shiftIn(dataPin, clockPin); // inside buttonsswitchVar3 = shiftIn(dataPin, clockPin); // special features buttons

// shift register 1 Outside buttons

if (switchVar1 != 0){stepamount = amountchecker(switchVar1); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

/// shift register 2 Inside buttons

if (switchVar2 != 0){stepamount = amountchecker(switchVar2); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

}

Page 175: Elevator Programming Code

if (switchVar3 != 0){stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

switch (switchVar3){case 1: // the Freight Up Button// make_nice Part Amotor_freight.step(f_speed, BACKWARD, SINGLE);freight_pos = freight_pos + f_speed;break;

case 2: //the Freight Down Button_// make_nice part Bmotor_freight.step(f_speed, FORWARD, SINGLE);freight_pos = freight_pos - f_speed;break;

//case 3:

case 4:stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressedpassdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE);//updatecurrent_pos = current_pos + 175;delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE); //updatecurrent_pos = current_pos + 175;delay(2000);

motor_passenger.step(700, FORWARD, SINGLE); //updatecurrent_pos = current_pos - 700;//updatedelay(2000);break;

case 8:/*

THIS IS OLD CODE.

stepamount = 3100;passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

Page 176: Elevator Programming Code

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of elevatorfreighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine travel amount;

motor_freight.step(freighttravel, freightdirection, SINGLE);freight_pos = stepamount; */

/* This is new code */

stepamount = 2600; // 6th floorpassdirection = elevator_direction(stepamount, current_pos);//determine travel direction of passenger elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amounttotalpasstravel = current_pos + passtravel;

freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of freight elevatorfreighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight travel amounttotalfreighttravel = freight_pos + freighttravel;

for (int go =0; go <= 3450; go++){if (current_pos < totalpasstravel) //pass travel and freighttravel do not work here.{motor_passenger.step(1, passdirection, SINGLE);current_pos = current_pos + 1; }if (freight_pos < totalfreighttravel){motor_freight.step(1, freightdirection, SINGLE);freight_pos = freight_pos + 1; }}

//Serial.print("Current Position of Passenger: ");//Serial.println(current_pos);///Serial.print("Current Position of Freight: ");//Serial.println(freight_pos);//delay(5000);

break;

case 16:bureaucratic_prostitution();break;case 32:coordinates_of_social_space();break;case 64:the_end_of_the_world();break;

case 128:// The_End_of_the_Worldstepamount = amountchecker(switchVar3); // returns preset value of floor where button was pressed

Page 177: Elevator Programming Code

passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of elevatorpasstravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount;

motor_passenger.step(passtravel, passdirection, SINGLE);current_pos = stepamount;

for (int hover = 0; hover <= 10; hover ++){motor_passenger.step(10, FORWARD, SINGLE);delay(500);motor_passenger.step(10, BACKWARD, SINGLE);delay(500);}

current_pos = stepamount;//Serial.print("Current Position of Passenger: ");//Serial.println(current_pos);//Serial.print("Current Position of Freight: ");//Serial.println(freight_pos);//delay(20);break;} // end switch (case) statement

//current_pos = stepamount;

} // end switchvar3 if statement} // end main loop

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function///// just needs the location of the data pin and the clock pin///// it returns a byte with each bit in the byte corresponding///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { int i;int temp = 0;int pinState;byte myDataIn = 0;pinMode(myClockPin, OUTPUT);pinMode(myDataPin, INPUT);//we will be holding the clock pin high 8 times (0,..,7) at the//end of each time through the for loop//at the begining of each loop when we set the clock low, it will//be doing the necessary low to high drop to cause the shift//register's DataPin to change state based on the value//of the next bit in its serial information flow.//The register transmits the information about the pins from pin 7 to pin 0//so that is why our function counts downfor (i=7; i>=0; i--) {

Page 178: Elevator Programming Code

digitalWrite(myClockPin, 0);delayMicroseconds(0.2); temp = digitalRead(myDataPin);if (temp) { pinState = 1;//set the bit to 0 no matter what myDataIn = myDataIn | (1 << i); }else {

pinState = 0; }

digitalWrite(myClockPin, 1);

}

return myDataIn;

}