Created
November 9, 2012 01:19
-
-
Save lizkhoo/4043113 to your computer and use it in GitHub Desktop.
PComp Midterm: Window Shade Pre-final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Intro to PComp Mid-term Fall 2012 | |
Liz Khoo, Natalie Tschechaniuk, Katie Adee | |
-----Responsive Moire Window Shade----- | |
Parts: | |
- 18"x18" frame with dowels | |
- 6-position rotary switch | |
- Parallax PIR motion sensor | |
- Unipolar step motor | |
- Arduino UNO | |
- Breadboard | |
*/ | |
#include <Stepper.h> | |
const int switchPin1 = 2; | |
const int switchPin2 = 3; | |
const int switchPin3 = 4; | |
const int switchPin4 = 5; | |
const int switchPin5 = 6; | |
const int switchPin6 = 7; | |
const int stepsPerRevolution = 100; //motor is Mabuchi # PF35T-48L4 w/3.6 degree steps | |
Stepper myStepper(stepsPerRevolution, 8,9,10,11); | |
int stepCount = 0; | |
int switch1Value = 0; | |
int switch2Value = 0; | |
int switch3Value = 0; | |
int switch4Value = 0; | |
int switch5Value = 0; | |
int switch6Value = 0; | |
int pirPin = 12; | |
int pirState = LOW; | |
int pirVal = 0; | |
void setup() { | |
pinMode(switchPin1, INPUT); | |
pinMode(switchPin2, INPUT); | |
pinMode(switchPin3, INPUT); | |
pinMode(switchPin4, INPUT); | |
pinMode(switchPin5, INPUT); | |
pinMode(switchPin6, INPUT); | |
pinMode(pirPin, INPUT); | |
Serial.begin(9600); | |
} | |
void loop(){ | |
//ON--slow 1 step/ 3 sec | |
if (switch2Value == 1){ | |
myStepper.step(1); | |
Serial.print("step count: "); | |
Serial.println(stepCount); | |
stepCount++; | |
delay(3000); | |
} | |
//ON--medium 1 step/ 1 sec | |
if (switch3Value == 1){ | |
myStepper.step(1); | |
Serial.print("step count: "); | |
Serial.println(stepCount); | |
stepCount++; | |
delay(1000); | |
} | |
//ON--motion responsive/high 1 step/half sec | |
pirVal = digitalRead(pirPin); | |
if (switch4Value == 1 && pirVal == HIGH){ | |
myStepper.step(1); | |
Serial.print("step count: "); | |
Serial.print(stepCount); | |
Serial.print(", pirVal: "); | |
Serial.println(pirVal); | |
stepCount++; | |
delay(500); | |
} | |
switch1Value = digitalRead(switchPin1); //OFF--aligned open | |
Serial.print("Position 1: "); | |
Serial.print(switch1Value); | |
Serial.print(","); | |
switch2Value = digitalRead(switchPin2); //ON--slow 1 step/ 3 sec | |
Serial.print("Position 2: "); | |
Serial.print(switch2Value); | |
Serial.print(","); | |
switch3Value = digitalRead(switchPin3); //ON--medium 1 step/ 1 sec | |
Serial.print("Position 3: "); | |
Serial.print(switch3Value); | |
Serial.print(","); | |
switch4Value = digitalRead(switchPin4); //ON--motion responsive/high 1 step/half sec | |
Serial.print("Position 4: "); | |
Serial.print(switch4Value); | |
Serial.print(","); | |
switch5Value = digitalRead(switchPin5); //OFF--aligned closed | |
Serial.print("Position 5: "); | |
Serial.print(switch5Value); | |
Serial.print(","); | |
switch6Value = digitalRead(switchPin6); // NONE | |
Serial.print("Position 6: "); | |
Serial.print(switch6Value); | |
Serial.println(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment