First and foremost, we've finished our arduino code that tells our chair how to behave when folks are sitting down, specifically after a certain point to start tipping forward, and then wait once the maximum tilt is reached, and then after our determined "break time" to move back into a comfortable sitting position.
Check it out here. (Side note: the time values are currently at 10 seconds to make testing easier for us. In real life, these delay values would be much longer.)
const int seat = 12;
const int fwdStop = 2;
const int revStop = 4;
//Define the motors
const int fwd = 7;
const int rev = 8;
//Define the stages in the process
int seatButton = 0;
int stopButton = 0;
int finishButton = 0;
//This activates the moter and keeps it on
boolean movingBackwards = false;
boolean movingForwards = false;
//seatButton "holding" stuff
int seatFirstTime = 1;
unsigned long seatStartTime;
unsigned long seatPressTime;
//stopButton "holding" stuff
int stopFirstTime = 1;
unsigned long stopStartTime;
unsigned long stopPressTime;
//===============================================
void setup() {
//Set pin modes
pinMode(seat, INPUT);
pinMode(fwdStop, INPUT);
pinMode(revStop, INPUT);
pinMode(fwd, OUTPUT);
pinMode(rev, OUTPUT);
Serial.begin(9600);
}
//===============================================
void loop(){
seatButton = digitalRead(seat);
stopButton = digitalRead(fwdStop);
finishButton = digitalRead(revStop);
/*
stopButton and finishButton: LOW == IN and HIGH == OUT
seatButton: HIGH == IN and LOW == OUT
*/
//Start and waiting process
if (movingForwards){
motorOnFwd();
} else {
motorOff();
}
//seatButton IN, finishButton IN
if (seatButton == HIGH && finishButton == LOW) {
if (seatFirstTime == 1) {
seatStartTime = millis();
seatFirstTime = 0;
}
seatPressTime = millis() - seatStartTime;
if (seatPressTime >= 1) {
}
seatPressTime = millis() - seatStartTime;
if(seatPressTime >= 1){
Serial.print("Time: ");
Serial.print(seatPressTime);
Serial.print(" milliseconds ");
Serial.print(int(seatPressTime/1000));
Serial.println(" seconds");
}
if (seatPressTime > 10000) {
movingForwards = true;
}
} else if (seatFirstTime == 0) {
seatFirstTime = 1;
movingForwards = true;
}
//Forward and stop process
//Wait and reverse process
if (movingBackwards){
motorOnRev();
} else {
motorOff();
}
//stopButton IN
if (seatButton == LOW && stopButton == LOW && finishButton == HIGH || stopButton == LOW) {
if (stopFirstTime == 1) {
stopStartTime = millis();
stopFirstTime = 0;
}
stopPressTime = millis() - stopStartTime;
if (stopPressTime >= 1) {
}
stopPressTime = millis() - stopStartTime;
if(stopPressTime >= 1){
Serial.print("Time: ");
Serial.print(stopPressTime);
Serial.print(" milliseconds ");
Serial.print(int(stopPressTime/1000));
Serial.println(" seconds");
}
if (stopPressTime > 10000) {
movingBackwards = true;
}
} else if (stopFirstTime == 0) {
stopFirstTime = 1;
movingBackwards = true;
}
/*
} else if (seatButton == LOW && stopButton == LOW) {
movingBackwards = true;
}
*/
/* IMPORTANT! DO NOT DELETE THIS SECTION
seatButton and finishButton act as killswitches so
the motor and battery does not commit suicide */
if (seatButton == HIGH && movingBackwards == true || finishButton == LOW) {
movingBackwards = false;
}
if (stopButton == LOW) {
movingForwards = false;
}
/* End of important section */
}
//===============================================
void motorOff() {
digitalWrite(fwd, HIGH);
digitalWrite(rev, HIGH);
}
void motorOnFwd() {
digitalWrite(fwd, LOW);
digitalWrite(rev, HIGH);
}
void motorOnRev() {
digitalWrite(fwd, HIGH);
digitalWrite(rev, LOW);
}
Now that our code is good to go, we've been working on the mechanical aspects of our chair: disassembling it, removing unneeded levers, and putting the chair back together. Currently we're attaching the motor and starting to manufacture the arm that will eventually tip the seat and backrest forward. Progress below!