Macroschlitten mit Arduino und Nextion Display

Macroschlitten mit Arduino und Nextion Display

Wozu braucht man einen Macroschlitten?

Der Aufbau

Funktion

Programmcode

				
					#include <Wire.h>
#include <Streaming.h>
int MS1 = 5;
int MS2 = 6;
int MS3 = 7;
int EN = 4;
int Step = 9;
int Dir =10;
int Index;
char button [7] = {};

void setup() {
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(MS3, OUTPUT);
  pinMode(EN, OUTPUT); //Enable
  pinMode(Step, OUTPUT); //Step
  pinMode(Dir, OUTPUT); //Direction

  digitalWrite(EN, LOW);
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0)
  {
    for (int i = 0; i < 6; i++) {
      button[i] = button[i + 1];
    }
    button[6] = Serial.read();
  }

  //10er Step UP
  if (button[2] == 1)
  {
    digitalWrite(Dir, LOW);
    for (Index = 0; Index < 10; Index++)
    {
      digitalWrite(Step, HIGH);
      delayMicroseconds(500);
      digitalWrite(Step, LOW);
      delayMicroseconds(500);
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
    }
  }

  //10er Step DOWN
  if (button[2] == 4)
  {
    digitalWrite(Dir, HIGH);
    for (Index = 0; Index < 10; Index++)
    {
      digitalWrite(Step, HIGH);
      delayMicroseconds(500);
      digitalWrite(Step, LOW);
      delayMicroseconds(500);
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
    }
  }

  //100er Step UP
  if (button[2] == 6)
  {
    digitalWrite(Dir, LOW);
    for (Index = 0; Index < 100; Index++)
    {
      digitalWrite(Step, HIGH);
      delayMicroseconds(500);
      digitalWrite(Step, LOW);
      delayMicroseconds(500);
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
    }
  }

  //100er Step DOWN
  if (button[2] == 7)
  {
    digitalWrite(Dir, HIGH);
    for (Index = 0; Index < 100; Index++)
    {
      digitalWrite(Step, HIGH);
      delayMicroseconds(500);
      digitalWrite(Step, LOW);
      delayMicroseconds(500);
    for (int (i = 0; i < 7; i++) {
      button[i] = 0;
    }
    }
  }

  //1000er Step UP
  if (button[2] == 9)
  {
    digitalWrite(Dir, LOW);
    for (Index = 0; Index < 1000; Index++)
    {
      digitalWrite(Step, HIGH);
      delayMicroseconds(500);
      digitalWrite(Step, LOW);
      delayMicroseconds(500);
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
    }
  }

  //1000er Step DOWN
  if (button[2] == 10)
  {
    digitalWrite(Dir, HIGH);
    for (Index = 0; Index < 1000; Index++)
    {
      digitalWrite(Step, HIGH);
      delayMicroseconds(500);
      digitalWrite(Step, LOW);
      delayMicroseconds(500);
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
    }
  }

  // Modus 1
  if (button[2] == 12)
  {
    String cmd;
    cmd += "\"";
    Serial.print("tModus.txt=" + cmd + "Modus 1" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.print("tModus.txt=" + cmd + "Modus 1" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    digitalWrite (MS1,LOW);
    digitalWrite (MS2,LOW);
    digitalWrite (MS3,LOW);  
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
  }

  // Modus 1/2
  if (button[2] == 13)
  {
    String cmd;
    cmd += "\"";
    Serial.print("tModus.txt=" + cmd + "Modus 1/2" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.print("tModus.txt=" + cmd + "Modus 1/2" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    digitalWrite (MS1,HIGH);
    digitalWrite (MS2,LOW);
    digitalWrite (MS3,LOW);  
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }  
  }
  
  // Modus 1/4
  if (button[2] == 14)
  {
    String cmd;
    cmd += "\"";
    Serial.print("tModus.txt=" + cmd + "Modus 1/4" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.print("tModus.txt=" + cmd + "Modus 1/4" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    digitalWrite (MS1,LOW);
    digitalWrite (MS2,HIGH);
    digitalWrite (MS3,LOW);   
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
  }
  
  // Modus 1/8
  if (button[2] == 15)
  {
    String cmd;
    cmd += "\"";
    Serial.print("tModus.txt=" + cmd + "Modus 1/8" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.print("tModus.txt=" + cmd + "Modus 1/8" + cmd);
    Serial.write(0xFF);
    Serial.write(0xFF);
    Serial.write(0xFF);
    digitalWrite (MS1,HIGH);
    digitalWrite (MS2,HIGH);
    digitalWrite (MS3,LOW);   
    for (int i = 0; i < 7; i++) {
      button[i] = 0;
    }
  }
}
				
			

Folgende Bauteile wurden verwendet: