As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Thursday, May 24, 2012

Aaron and Kelly: Working on Arduino

So we've been working hard at our coding for a while now, with mixed success. Our physical wiring and Arduino setup appears to be sound, with each switch and relay working when tested with simple code.

However, connecting everything to work in tandem the way we hope is not going quite as smoothly. Here is our code to date.


//Define the sensors
const int seat = 12;
const int fwdStop = 2;
const int revStop = 4;

//Interrupt sensor
int shiftStageTwo = 0;

//Define the motors
const int fwd = 7;
const int rev = 8;

//Define the stages in the process
int stageOne = 0;
int stageTwo = 0;
int stageThree = 0;

//Interrupt stuff
volatile int shiftStagetwo = fwdStop;

void setup() {
//Set pin modes
pinMode(seat, INPUT);
pinMode(fwdStop, INPUT);
pinMode(revStop, INPUT);
pinMode(fwd, OUTPUT);
pinMode(rev, OUTPUT);
//Set interrupts
attachInterrupt(stageTwo, swap, LOW);
}

//Interrupt function
void swap() {
if (shiftStagetwo == fwdStop) {
digitalWrite(fwd, HIGH);
digitalWrite(rev, HIGH);
}
else {
digitalWrite(fwd, HIGH);
digitalWrite(rev, HIGH);
}
}

void loop(){
stageOne = digitalRead(seat);
stageTwo = digitalRead(fwdStop);
stageThree = digitalRead(revStop);
if (stageOne == HIGH) {
//delay(5000); //delays don't work if multiple delays are present
digitalWrite(fwd, LOW);
digitalWrite(rev, HIGH);
}
else {
digitalWrite(fwd, HIGH);
digitalWrite(rev, HIGH);
}
if (stageTwo == LOW) {
digitalWrite(fwd, HIGH);
digitalWrite(rev, LOW);
}
else {
digitalWrite(fwd, HIGH);
digitalWrite(rev, HIGH);
}

// if (stageThree == LOW) {
// delay(5000);
// digitalWrite(fwd, HIGH);
// digitalWrite(rev, LOW);
// detachInterrupt(stageTwo);
// }
// else {
// digitalWrite(fwd, HIGH);
// digitalWrite(rev, HIGH);
// }
}

The interrupt function has effectively let us switch between motors, but things are still not quite up to par. Dominic's recommendation is to simplify our code and reduce most of our methods to if and while loops. That's next on our plate!

No comments:

Post a Comment