//License: Creative Commons CC-BY-SA-compatible Open Source Ecology (OSE) License //Purpose: for testing Open Source Ecology's CEB Press //Orientation: when you face the CEB Press, the ejection side is to your left //Motion Control: the CEB Press has 5 motions- it can move its primary cylinder up and down, its secondary cylinder left and right, and rotate its shaker motor //Sensors: the CEB Press has 2 hall effect sensors; on the primary cylinder and the secondary cylinder. The sensors switch and latch on and off when magnets move past them. //Test Selection: type true or false for the tests you want to do or not //Timed Movement, One-Time: boolean startdown = false; //Primary Cylinder Down int downtime = 6000; //For how long in milliseconds? boolean startup = false;//Primary Cylinder Up int uptime = 1000; boolean startright = false; //Secondary Cylinder Right int righttime = 4000; //For how long in milliseconds? boolean startleft = false;//Secondary Cylinder Left int lefttime = 1000; boolean startshake = false; //Shaker Motor Spins int shaketime = 3000; //For how long in milliseconds? //Sensor Tests, Repeating: boolean repeatsensor = false; //Want to see the sensor signals without motion? boolean primary trigger = false; //Want to see when the microcontroller "triggers" in response to the primary sensor? boolean secondary trigger = true; //Want to see when the microcontroller "triggers" in response to the secondary sensor? //Sensed Movement, Repeating: boolean repeatprimary = false; //Want the primary cylinder to cycle up and down according to the primary sensor and magnets? boolean repeatsecondary = false; //Want the secondary cylinder to cycle left and right according to the secondary sensor and magnets? boolean operation = false; //Want to continuously press bricks? This is the regular operation //Test and Operation Variables: int cycledelay = 100; //How much time between each motion (up, down, left, or right) in milliseconds? int compresstime = 4000; //How much time for the primary cylinder to compress upwards from its bottom position int releasetime = 1000; // How much time for the primary cylinder to release downwards from its compressed position //Pin Variables: int down = 3; int up = 6; int left = 9; int right = 10; int shake = 11; int S1 = A0; //Set the primary sensor pin int S2 = A1; //Set the secondary sensor pin //Data Processing Variables int samplenumber = 10; //How many samples per reading? int samples[10]; //Variables to store each sample value - this should equal samplenumber int sampledelay = 5;//Time delay between getting each sample in milliseconds float HighTrigger = 1.0; //Sensor upper threshold in volts * 1024 / 5 float LowTrigger = 0.1; //Sensor lower threshold in volts * 1024 / 5 int i; //Variable for sample repetition count float Reading = 0; //Variable to store averaged signal value int activesensor = 0; //Variable that tells which sensor should be read by the averaging function //Signal Averaging Function: void average(){ Reading = 0; for(i = 0;i HighTrigger){ break; } } } void belowtrigger(){ while(1==1){ average(); if (Reading < LowTrigger){ break; } } } //Starting Setup! void setup(){ //Serial communication on! Serial.begin(9600); //Pins assigned as inputs! pinMode(S1,INPUT);//Primary Sensor pinMode(S2,INPUT);//Secondary Sensor //Pins assigned as outputs! pinMode(down, OUTPUT);//Primary Down pinMode(up, OUTPUT);//Primary Up pinMode(left, OUTPUT);//Secondary Left pinMode(right, OUTPUT);//Secondary Right pinMode(shake, OUTPUT);//Shaker //Timed Movements: //Starting Motion: Primary Down! if (startdown == true){ Serial.println("Down Time"); digitalWrite(down, HIGH); delay(downtime); digitalWrite(down, LOW); } //Starting Motion: Primary Up! if (startup == true){ Serial.println("Up Time"); digitalWrite(up, HIGH); delay(uptime); digitalWrite(up, LOW); } //Starting Motion: Secondary Right! if (startright == true){ Serial.println("Right Time"); digitalWrite(right, HIGH); delay(righttime); digitalWrite(right, LOW); } //Starting Motion: Secondary Left! if (startleft == true){ Serial.println("Left Time"); digitalWrite(left, HIGH); delay(lefttime); digitalWrite(left, LOW); } //Starting Motion: Shaker Spin! if (startshake == true){ Serial.println("Shake Time"); digitalWrite(shake, HIGH); delay(shaketime); digitalWrite(shake, LOW); } }//Setup Complete //Starting Loop! void loop(){ //Sensor Signal Measuring Cycle! if (repeatsensor == true){ Serial.println("Primary Sensor"); activesensor = S1; average(); Serial.println("Reading"); Serial.println("Secondary Sensor"); activesensor = S2; average(); Serial.println("Reading"); } //Primary Sensor Trigger Cycle! if(primarytrigger == true){ Serial.println("Primary Sensor"); activesensor = S1; abovetrigger(); Serial.println("Above Triggered"); belowtrigger(); Serial.println("Below Triggered"); } //Secondary Sensor Trigger Cycle! if(secondarytrigger == true){ Serial.println("Secondary Sensor"); activesensor = S2; abovetrigger(); Serial.println("Above Triggered"); belowtrigger(); Serial.println("Below Triggered"); } //Primary Cylinder Basic Cycle! if (repeatprimary == true){ Serial.println("Up Full"); activesensor = S1; digitalWrite(up, HIGH); abovetrigger(); Serial.println("Above Triggered"); belowtrigger(); Serial.println("Below Triggered"); abovetrigger(); Serial.println("Above Triggered"); digitalWrite(up, LOW); delay(cycledelay); Serial.println("Down Full"); digitalWrite(down, HIGH); abovetrigger(); Serial.println("Above Triggered"); belowtrigger(); Serial.println("Below Triggered"); abovetrigger(); Serial.println("Above Triggered"); digitalWrite(down, LOW); delay(cycledelay); } //Secondary Cylinder Basic Cycle! if (repeatecondary == true){ Serial.println("Left Full"); activesensor = S2; digitalWrite(left, HIGH); abovetrigger(); Serial.println("Above Triggered"); belowtrigger(); Serial.println("Below Triggered"); abovetrigger(); Serial.println("Above Triggered"); digitalWrite(left, LOW); delay(cycledelay); Serial.println("Right Full"); digitalWrite(right, HIGH); abovetrigger(); Serial.println("Above Triggered"); belowtrigger(); Serial.println("Below Triggered"); abovetrigger(); Serial.println("Above Triggered"); digitalWrite(right, LOW); delay(cycledelay); } //Continuous Brick Pressing! if (operation == true){ Serial.println("Left Full"); activesensor = S2; digitalWrite(left, HIGH); abovetrigger(); belowtrigger(); abovetrigger(); digitalWrite(left, LOW); Serial.println("Down Full"); activesensor = S1; digitalWrite(down, HIGH); abovetrigger(); belowtrigger(); abovetrigger(); digitalWrite(down, LOW); Serial.println("Shake Time"); digitalWrite(shake, HIGH); delay(shaketime); digitalWrite(shake, LOW); Serial.println("Right Mid"); activesensor = S2; digitalWrite(right, HIGH); abovetrigger(); belowtrigger(); digitalWrite(right, LOW); Serial.println("Up Compress"); activesensor = S1; digitalWrite(up, HIGH); delay(compresstime); digitalWrite(up, LOW); Serial.println("Down Release"); digitalWrite(down, HIGH); delay(releasetime); digitalWrite(down, LOW); Serial.println("Right Max"); activesensor = S2; digitalWrite(right, HIGH); abovetrigger(); digitalWrite(right, LOW); Serial.println("Up Max"); activesensor = S1; digitalWrite(up, HIGH); abovetrigger(); digitalWrite(up, LOW); } } //Repeating the loop!