kinetic//organic>>programing help.

hello everyone:)

i am relatively new to programing, well about the only thing i could fully program was Lego mindstorms :P. anyway, i have been working on this art project for close to a year now, and well its in its final stages. named "kinetic//organic" it has 4 separate sculptures, each representing a different human organ eg: brain (piano rolls, lightbulbs and an arduino), heart (4 glass reservoirs, two water pumps and two syringes controlled by a gearbox) lungs (two bicycle pumps and several pc fans) and stomach (a lavalamp). all these sculptures are inter connected, for example the syringes on the heart control the water level in the stomach and the air pumps blow bubbles into the heart, ect. here are some photo's to help you understand

brain, heart, lungs & stomach

heart syringes.

lungs.

anyway the problem im having is that i need to create a program as follows:

wait 1 second run gearbox forward when top switch is hit stop gearbox wait 2 seconds reverse gearbox

this program is needed to control the "breating" of the pumps in the lungs as well as the syringe plungers in the heart. both of which have a "stopping switch". the program i came up with is as follows:

/* Brealthing * ------------ * * motor runs clockwise until sw 1 is hit, it then stops, waits three * seconds and the motor reverses until it hits sw 2. it then stops, * waits three seconds and repeats the program

* */

int RELAY1Pin = 2; // relay connected to pin 1 int RELAY2Pin = 3; // relay connected to pin 2 int topSWpin = 10; int botSWpin = 11; int val = 0; // variable for reading the pin status

void setup(){

pinMode(topSWpin, INPUT); pinMode(botSWpin, INPUT); pinMode(RELAY1Pin, OUTPUT); // sets the digital pin as output pinMode(RELAY2Pin, OUTPUT); // sets the digital pin as output }

void loop(){

val = digitalRead(topSWpin); if (val == HIGH) { digitalWrite(RELAY1Pin, LOW); digitalWrite(RELAY2Pin, HIGH); } else {

} val = digitalRead(botSWpin); if (val == HIGH) { digitalWrite(RELAY2Pin, LOW); digitalWrite(RELAY1Pin, HIGH); } else {

} }

when attempting to run this program on the "lungs" part of the sculpture it hit the stop switch but didn't stop, ripping the teeth off the pinion gear of the gearbox. i have checked all the connections and even ran tests on the switches and motor control relays which proved they were all working fine. in the writing of this program i did not attempt to include the delays, as it was pausing before it ran the program and just confusing in general.

any advice anyone?

Perhaps something like this:

/* Breathing 
 * ------------ 
 * 
 * motor runs clockwise until sw 1 is hit, it then stops, waits three 
 * seconds and the motor reverses until it hits sw 2. it then stops,  
 * waits three seconds and repeats the program 

 * 
 */ 

int RELAY1Pin = 2;                 // relay connected to pin 1 
int RELAY2Pin = 3;                 // relay connected to pin 2 
int topSWpin = 10; 
int botSWpin = 11; 
int val = 0;     // variable for reading the pin status 

void motorCW(){
    digitalWrite(RELAY1Pin, LOW);  
    digitalWrite(RELAY2Pin, HIGH);   
}

void motorCCW(){
    digitalWrite(RELAY2Pin, LOW);  
    digitalWrite(RELAY1Pin, HIGH);   
}

void motorStop(){
    digitalWrite(RELAY2Pin, LOW);   
    digitalWrite(RELAY1Pin, LOW); 
}

void setup(){ 
   
  pinMode(topSWpin, INPUT); 
  pinMode(botSWpin, INPUT); 
  pinMode(RELAY1Pin, OUTPUT);      // sets the digital pin as output 
  pinMode(RELAY2Pin, OUTPUT);      // sets the digital pin as output   
} 

void loop(){ 
  
 while( digitalRead(topSWpin) != HIGH)  
   motorCW();  // while not at the top drive motor CW
   
 motorStop();  // stop the motor
 delay(3000);  // wait 3 seconds

 while( digitalRead(botSWpin) != HIGH)    
   motorCCW();  // while not at the bottom drive motor CCW
   
 motorStop();
 delay(3000);  
}

You need to check that the sense of the switches are correct, I assumed that topSWpin goes high when fully CW. I made assumptions on the realy sense that you may need to change. But I hope this gets you going in the right direction