Close

Arduino code had been added to the files

A project log for Delta belt 3D-printer for automated production

Combine the speed of a Delta printer with the automation of a conveyor belt

brian-brockenBrian Brocken 05/16/2022 at 20:230 Comments
// Defines pins numbers
const int stepPin = 3;
const int dirPin = 4; 
const int Enable = 5;
const int GLED = 6;
const int RLED = 7;
const int LmtSwtch = A1;
const int Mspeed = 500; //delay between pulses to determine the motor speed (smaller delay = faster motor)
int Lastbuttonstate = 1;
int flag1 = 0;
int StepAmount = 0;
int StepAmountSet = 6000; //Amount of steps that have to be taken (distance the belt travels when switch is triggered)
int customDelay,customDelayMapped; // Defines variables
 
void setup() {
  // Sets the pins as outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(Enable, OUTPUT);
  pinMode(LmtSwtch, INPUT_PULLUP);
  pinMode(GLED, OUTPUT);
  pinMode(RLED, OUTPUT);
  
  //Serial.begin(115200); //uncomment line to use serial monitor
 
  digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
  digitalWrite(RLED,HIGH);
  digitalWrite(GLED,HIGH);
}
void loop() {

  int Buttonstate = digitalRead(LmtSwtch);

  if (Buttonstate < Lastbuttonstate){
    flag1 = 1;
  }

  Lastbuttonstate = Buttonstate;
  
  if (flag1 == 0)
  {
    digitalWrite(Enable, LOW);
    digitalWrite(stepPin, LOW);
  }
  if (flag1 == 1 && StepAmount < StepAmountSet)
  {
      digitalWrite(Enable, LOW);
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(Mspeed);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(Mspeed);
      StepAmount = StepAmount + 1;
  }
  else {
    flag1 = 0;
    StepAmount = 0;
  }

  /*
  Serial.print("Buttonstate: "); //uncomment this section to use serial monitor
  Serial.print(Buttonstate);
  Serial.print(" flag1: ");
  Serial.print(flag1);
  Serial.print(" StepAmount: ");
  Serial.println(StepAmount);
  */
  
}

Discussions