CEB Press/Manufacturing Instructions/Control Source Code v1.01

From Open Source Ecology
< CEB Press‎ | Manufacturing Instructions
Revision as of 13:16, 6 October 2009 by WikiSysop (talk | contribs) (Created page with '// State Machine for CEB Press // Open Source Ecology / Factor-E Farm // Benjamin Gatti - 10-5-2009 // This code is provided free to use and modify under the GPL int State = 0;...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

// State Machine for CEB Press // Open Source Ecology / Factor-E Farm // Benjamin Gatti - 10-5-2009 // This code is provided free to use and modify under the GPL


int State = 0; float TFactor = .6; boolean Run = 1;

  1. define STATEMIN 1
  2. define STATEDOWN 1 //Drop the press all the way down

int TD = 3000;

  1. define STATELOAD 2 //Wait/Jiggle for chamber to fill

int TL = 250;

  1. define STATECLOSE 3 //Move Drawer to closed position - (Move for TC millis)

int TC = 660;

  1. define STATEPRESS 4 //Raise the press

int TP = 5000;

  1. define STATERELEASE 5 //Drop the Press slightly (TR millis)

int TR = 120;

  1. define STATEOUT 6 //Move Drawer to open position - fully Out

int TO = 2000;

  1. define STATEUP 7 //Raise the press all the way Up - lifting the Brick above the eject trough

int TU = 600;

  1. define STATEEJECT 8 //Move Drawer - full In

int TE = 500;

  1. define STATEMAX STATEEJECT

int solPressUp = 5; int solPressDown = 6; int solDrawerIn = 10; int solDrawerOut = 11; int Timer = 0; //clock for current state int ledPin = 13; // LED connected to digital pin 13

void setup() // run once, when the sketch starts {

 shutdown();
 pinMode(ledPin, OUTPUT);      // sets the digital pin as output

 pinMode(solPressUp, OUTPUT);      // sets the digital pin as output
 pinMode(solPressDown, OUTPUT);      // sets the digital pin as output
 pinMode(solDrawerIn, OUTPUT);      // sets the digital pin as output
 pinMode(solDrawerOut, OUTPUT);      // sets the digital pin as output
 Run = 1; 
 Serial.begin (19200);
 Serial.println("Started");
 State = STATEMIN;
 shutdown();
 Timer = 100;

} void shutdown(){

 digitalWrite(solPressUp,LOW);
 digitalWrite(solPressDown,LOW);
 digitalWrite(solDrawerIn,LOW);
 digitalWrite(solDrawerOut,LOW);

}

void Transition() {

 shutdown();
 //  Serial.writeln (State,DEC)
 switch (State)    {
 case STATEDOWN:  //Drop the press all the way down
   {
     Timer = TD * TFactor;
     digitalWrite(solPressDown,HIGH);
     Serial.println("Down");
     break;
   }
 case STATELOAD: //Wait/Jiggle for chamber to fill
   {
     Timer = TL * TFactor;
     Serial.println("Load");
     break;
   }
 case STATECLOSE:  //Move Drawer to closed position - (Move for TC millis)
   {
     Timer = TC * TFactor;
     digitalWrite(solDrawerIn,HIGH);
     Serial.println("Close");
     break;
   }
 case STATEPRESS: //Raise the press
   {
     Timer = TP * TFactor;
     digitalWrite(solPressUp,HIGH);
     Serial.println("Press");
     break;
   }
 case STATERELEASE: //Drop the Press slightly (TR millis)
   {
     Timer = TR * TFactor;
     digitalWrite(solPressDown,HIGH);
     Serial.println("Release");
     break;
   }
 case STATEOUT:   //Move Drawer to open position - fully Out
   {
     Timer = TO * TFactor;
     digitalWrite(solDrawerOut,HIGH);
     Serial.println("Out");
     break;
   }
 case STATEUP:  //Raise the press all the way Up - lifting the Brick above the eject trough
   {
     Timer = TU * TFactor;
     digitalWrite(solPressUp,HIGH);
     Serial.println("Up");
     break;
   }
 case STATEEJECT:   //Move Drawer - full In
   {
     Timer = TE * TFactor;
     digitalWrite(solDrawerIn,HIGH);
     Serial.println("Eject");
     break;
   }
 default:
   Run =0;
   Serial.println("Error on State Case Shut Down");
   break;
 }

}

void loop() // run over and over again {

 if(Run==1)
 {
   if (Timer>0){
     delay(1);
     Timer--;
   }
   else
   {
     State++;
     if (State > STATEMAX) {
       State=STATEMIN;
     }
     Transition();
   }
 }
 else
 {
   digitalWrite(solPressUp,LOW);
   digitalWrite(solPressDown,LOW);
   digitalWrite(solDrawerIn,LOW);
   digitalWrite(solDrawerOut,LOW);
 }


 //  digitalWrite(ledPin, HIGH);   // sets the LED on
 //  digitalWrite(Chnl0, HIGH);   // sets the LED on
 //  delay(500);                  // waits for a second
 //  digitalWrite(ledPin, LOW);   // sets the LED on
 //  digitalWrite(Chnl0, LOW);   // sets the LED on
 //  delay(500);                  // waits for a second


}