0% found this document useful (0 votes)
2K views

Elevator Programming Code

The document contains Arduino code for controlling stepper motors and DC motors using an Adafruit motor shield. It defines classes for the DC and stepper motors that allow setting speed and direction. It also defines functions for the motor shield to enable outputs and latch data to control the motor driver chips. The code samples show initializing and running the motors by calling methods of the motor classes.

Uploaded by

100mph
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Elevator Programming Code

The document contains Arduino code for controlling stepper motors and DC motors using an Adafruit motor shield. It defines classes for the DC and stepper motors that allow setting speed and direction. It also defines functions for the motor shield to enable outputs and latch data to control the motor driver chips. The code samples show initializing and running the motors by calling methods of the motor classes.

Uploaded by

100mph
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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);

}
#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);

}
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]


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]


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]


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]


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]


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]


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]


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]


// 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
}
// 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
}
// 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);
// 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);
}
}
// 15 March Shift Register B
//define where your pins are
int 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
//troubleshoot
byte 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 space
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);

}
//debuging print statements whitespace
//Serial.println();
//Serial.println(myDataIn, BIN);
return myDataIn;
}
//15 March Shift Register 1

//define where your pins are


int 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
//troubleshoot
byte 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
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);

}
//debuging print statements whitespace
//Serial.println();
//Serial.println(myDataIn, BIN);
return myDataIn;
}
// 1 April Shift Register Trials A

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
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);

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;}
// 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;
}
//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;
}
// 1 April Shift Register Trials A1

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
// 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;
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;
}
// 1 April Shift Register Trial B

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
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);

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;}
// 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
//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;
}
// 3 April Shift Register Trail A

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
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;
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;
}
// 4 April Shift Register A

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
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;
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;
}
// 6 April Shift Register Trial

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
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;
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;
}
// 7 April Shift Register Trial A

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
// 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;
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;
}
// 9 April Shift Register Trial A

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
// 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;
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;
}
// 9 April Switch Trial B

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
// 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;
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;
}
// 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);

}
// 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);

}
// Elevator Test_1

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
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);

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;}
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;
}
//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;
}
// Elev Test 2

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
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);

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;}
// 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;
}
//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;
}
// 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
//int Freight_elevator_Is = 0; // position of elevator at current point in time. this will c

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 screen


Serial.print("Passenger Direction: ");
Serial.println(passDirection);
delay(5000);
Serial.print("Freight Direction: ");
Serial.println(freightDirection);
delay(5000);

}
// 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 Backw
int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start
int stepamount; // variable that holds outside button push

//Define variables to hold the data


//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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;
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() {
//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 != 0)
{
stepamount = amountchecker(switchVar1); // amount of travel necessary
Serial.print("Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs t


Serial.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);

}
}

//------------------------------------------------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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 15 April Shift Register Trials A

//define where your pins are


int 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
//troubleshoot
byte switchVar1 = 72; //default number first comparison first ride of the day
byte 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;}
//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;}
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);
digitalWrite(myClockPin, 1);

}
//debuging print statements whitespace
//Serial.println();
//Serial.println(myDataIn, BIN);
return myDataIn;
}
// 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 Backw
int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start
int stepamount; // variable that holds outside button push

//Define variables to hold the data


//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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)


{
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() {
//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 != 0)
{
stepamount = amountchecker(switchVar1); // amount of travel necessary
Serial.print("Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs t


Serial.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 2

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

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs t


Serial.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
//}
// 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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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 Backw
int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start
int stepamount; // variable that holds value assigned to floor where the outside button is pu

//Define variables to hold the data


//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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)


{
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()
{

//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 != 0)
{
stepamount = amountchecker(switchVar1); // amount of travel necessary
Serial.print("Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs t


Serial.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);

}
/// shift register 2

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

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs t


Serial.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;
//}
// 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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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 Backw
int current_pos = 1000; // current position of eleveator. set to 1000 ground floor at start
int stepamount; // variable that holds value assigned to floor where the outside button is pu

//Define variables to hold the data


//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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)


{
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()
{

//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 != 0)
{
stepamount = amountchecker(switchVar1); // amount of travel necessary
Serial.print("Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs t


Serial.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);

}
/// shift register 2

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

passdirection = elevator_direction(stepamount, current_pos); // get direction elevator needs t


Serial.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;
//}
// 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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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 Backw
int current_pos = 1000; // current position of elevator. set to 1000 ground floor at start u
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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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)
{
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()
{
}

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 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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
Serial.print("Outside Button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
Serial.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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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 pre
Serial.print("Inside button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


Serial.print("Inside button 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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging
delay(500);

motor_passenger.step(travel, passdirection, SINGLE);


current_pos = stepamount;

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 pre
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.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); //debugging
delay(1000); //debugging
digitalWrite (ledPin,0); //debugging

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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 Backw
int current_pos = 1000; // current position of elevator. set to 1000 ground floor at start u
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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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)
{
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()
{
}
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 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); // outside buttons
switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
Serial.print("Outside Button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


Serial.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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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 pre
Serial.print("Inside button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


Serial.print("Inside button 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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);


current_pos = stepamount;

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 pre
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.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);


current_pos = stepamount;

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

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);
}

return myDataIn;

}
// 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 Backw
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 elevator


int f_speed = 10; // speed of freight elevator

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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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)
{
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()
{
}

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 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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
Serial.print("Outside Button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


Serial.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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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 pre
Serial.print("Inside button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


Serial.print("Inside button 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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);


current_pos = stepamount;

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 pre
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.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 wa
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.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: "); //debugging


Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);


current_pos = stepamount;

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


Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of el


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 - freight_pos; // calculate number of steps elevator needs to travel if
}
else
{
travel = freight_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging

delay(500);

motor_freight.step(travel, passdirection, 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 = amountchecker(switchVar3); // returns preset value of floor where button was
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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
delay(1000); //debugging
digitalWrite (ledPin,0); //debugging

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

}
return myDataIn;

}
// 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 Backw
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 elevator


int f_speed = 10; // speed of freight elevator

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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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)
{
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()
{
}

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 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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
Serial.print("Outside Button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


Serial.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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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 pre
Serial.print("Inside button Step Amount value: "); //debugging
Serial.println(stepamount); //debugging
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
Serial.print("Inside button 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
}
else
{ travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);


current_pos = stepamount;

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 pre
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.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 wa
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.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: "); //debugging


Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging

delay(500);

motor_passenger.step(travel, passdirection, SINGLE);


current_pos = stepamount;

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


Serial.println(stepamount); //debugging

passdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of el


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 - freight_pos; // calculate number of steps elevator needs to travel if
}
else
{
travel = freight_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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


Serial.println(travel); //debugging

delay(500);

motor_freight.step(travel, passdirection, 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 = amountchecker(switchVar3); // returns preset value of floor where button was
Serial.print("SwitchVar3 Step Amount value: "); //debugging
Serial.println(stepamount); //debugging

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


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
}
else
{
travel = current_pos - stepamount; // calculate number of steps elevator needs to travel if
}

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
delay(1000); //debugging
digitalWrite (ledPin,0); //debugging

digitalWrite(ledPin,1); //debugging
delay(1000); //debugging
digitalWrite (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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

}
return myDataIn;

}
// 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
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 elevator


int f_speed = 10; // speed of freight elevator

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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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


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 dir
}
else
{
travel = position - stepamount; // calculate number of steps elevator needs to travel if di
}

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;
}
// 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);
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 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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount
motor_passenger.step(passtravel, passdirection, SINGLE);
current_pos = stepamount;

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

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;

case 4:
stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 el
passtravel = 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
freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine travel

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 floor
passdirection = elevator_direction(stepamount, current_pos);//determine travel direction of pa
passtravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amo
freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of
freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight

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 goi
}
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
}
}

//------------------------------------------------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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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
int totalfreighttravel = 0; // freight_pos + freighttravel for moving freight elevator to a d
int passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or
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 elevator
int 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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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


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 dir
}
else
{
travel = position - stepamount; // calculate number of steps elevator needs to travel if di
}

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;
}
// 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
//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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount

motor_passenger.step(passtravel, passdirection, SINGLE);


current_pos = stepamount;

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

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;

case 4:
stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 e
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amoun

motor_passenger.step(passtravel, passdirection, SINGLE);


current_pos = stepamount;

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


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

motor_freight.step(freighttravel, freightdirection, SINGLE);


freight_pos = stepamount; */

/* This is new code */

stepamount = 3400; // 8th floor


passdirection = elevator_direction(stepamount, current_pos);//determine travel direction of pa
passtravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amo
totalpasstravel = current_pos + passtravel;

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


freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight
totalfreighttravel = 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 goin
}
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
}
}

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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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(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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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
int freightdirection= 0; // direction freight elevator will travel.
int current_pos = 650; // current position of elevator. set to 650 basement floor at start u
int stepamount; // variable that holds value assigned to floor where a button is pushed.

int freight_pos = 1000; // current position of freight elevator


int f_speed = 10; // speed of freight elevator

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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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


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 dir
}
else
{
travel = position - stepamount; // calculate number of steps elevator needs to travel if di
}

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;
}
// 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);
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 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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount
motor_passenger.step(passtravel, passdirection, SINGLE);
current_pos = stepamount;

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

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;

case 4:
stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 floor
passdirection = elevator_direction(stepamount, current_pos);//determine travel direction of pa
passtravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amo
freightdirection = elevator_direction(stepamount, freight_pos); // returns travel direction of
freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight

for (int go =0; go <= 3450; go++)


{
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 goi
}
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
}
}
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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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
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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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
int totalfreighttravel = 0; // freight_pos + freighttravel for moving freight elevator to a d
int passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or
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 elevator
int 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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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


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 dir
}
else
{
travel = position - stepamount; // calculate number of steps elevator needs to travel if di
}

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;
}
// 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
//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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount

motor_passenger.step(passtravel, passdirection, SINGLE);


current_pos = stepamount;

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

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;

case 4:
stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 e
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amoun

motor_passenger.step(passtravel, passdirection, SINGLE);


current_pos = stepamount;

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


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

motor_freight.step(freighttravel, freightdirection, SINGLE);


freight_pos = stepamount; */

/* This is new code */

stepamount = 3100; // 8th floor


passdirection = elevator_direction(stepamount, current_pos);//determine travel direction of pa
passtravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amo
totalpasstravel = current_pos + passtravel;

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


freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight
totalfreighttravel = 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 goin
}
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
}
}

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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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(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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

}
// 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
int totalfreighttravel = 0; // freight_pos + freighttravel for moving freight elevator to a d
int passdirection = 0; // direction passenger elevator will travel. will be 1 is Forward or
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 elevator
int 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

byte switchVar1 = 0; //default number first comparison first ride of the day
byte 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


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 dir
}
else
{
travel = position - stepamount; // calculate number of steps elevator needs to travel if di
}

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;
}
// 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
//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); // outside buttons


switchVar2 = shiftIn(dataPin, clockPin); // inside buttons
switchVar3 = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amount

motor_passenger.step(passtravel, passdirection, SINGLE);


current_pos = stepamount;

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

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

case 2: //the Freight Down Button_


// make_nice part B
motor_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 pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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);//update


current_pos = current_pos + 175;
delay(2000);

motor_passenger.step(175, BACKWARD, SINGLE); //update


current_pos = current_pos + 175;
delay(2000);

motor_passenger.step(700, FORWARD, SINGLE); //update


current_pos = current_pos - 700;//update
delay(2000);
break;

case 8:
/*

THIS IS OLD CODE.

stepamount = 3100;
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of e
passtravel = travel_amount(stepamount, current_pos, passdirection); // determine travel amoun
motor_passenger.step(passtravel, passdirection, SINGLE);
current_pos = stepamount;

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


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

motor_freight.step(freighttravel, freightdirection, SINGLE);


freight_pos = stepamount; */

/* This is new code */

stepamount = 2600; // 6th floor


passdirection = elevator_direction(stepamount, current_pos);//determine travel direction of pa
passtravel = travel_amount(stepamount, current_pos, passdirection);//determine pass travel amo
totalpasstravel = current_pos + passtravel;

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


freighttravel = travel_amount(stepamount, freight_pos, freightdirection); // determine freight
totalfreighttravel = 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_World


stepamount = amountchecker(switchVar3); // returns preset value of floor where button was pre
passdirection = elevator_direction(stepamount, current_pos); // returns travel direction of el
passtravel = 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 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 {

pinState = 0;
}

digitalWrite(myClockPin, 1);

return myDataIn;

You might also like