Schrittmotor ansteuern mit Arduino + A4988

Schrittmotor ansteuern mit Arduino + A4988

Beschaltung

M1
M2
M3
Schrittweite
0
0
0
1 Vollschritt
1
0
0
1/2 Halbschritt
0
1
0
1/4 Viertelschritt
1
1
0
1/8 Achtelschritt
1
1
1
1/16 Sechzehntelschritt

Funktion

Programmcode
				
					#include <Wire.h>
#include "Adafruit_MPR121.h"

Adafruit_MPR121 cap = Adafruit_MPR121();

uint16_t lasttouched = 0;
uint16_t currtouched = 0;

int Index;
int touch;

void setup()
{
  Serial.begin(9600);
  if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");

  pinMode(6, OUTPUT); //Enable
  pinMode(5, OUTPUT); //Step
  pinMode(4, OUTPUT); //Direction

  digitalWrite(6, LOW);
}

void loop()
{
  currtouched = cap.touched();

  for (uint8_t i = 0; i < 12; i++) {
    // it if *is* touched and *wasnt* touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
      Serial.print(i); Serial.println(" touched");
      touch = i;
    }
  }
  if (touch == 1) {
    digitalWrite(4, HIGH);
    for (Index = 0; Index < 10; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
  if (touch == 2) {
    digitalWrite(4, LOW);
    for (Index = 0; Index < 10; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
    if (touch == 3) {
    digitalWrite(4, HIGH);
    for (Index = 0; Index < 100; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
  if (touch == 4) {
    digitalWrite(4, LOW);
    for (Index = 0; Index < 100; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
    if (touch == 5) {
    digitalWrite(4, HIGH);
    for (Index = 0; Index < 1000; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
  if (touch == 6) {
    digitalWrite(4, LOW);
    for (Index = 0; Index < 1000; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
    if (touch == 7) {
    digitalWrite(4, HIGH);
    for (Index = 0; Index < 10000; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
  if (touch == 8) {
    digitalWrite(4, LOW);
    for (Index = 0; Index < 10000; Index++)
    {
      digitalWrite(5, HIGH);
      delayMicroseconds(500);
      digitalWrite(5, LOW);
      delayMicroseconds(500);
      touch = 0;
    }
  }
  delay(100);
}
				
			

Jetzt im Onlineshop

OV2640 21mm 66 Grad Kamera für ESP32-Cam

3,59 
Umsatzsteuerbefreit gemäß UStG §19
zzgl. Versand
Lieferzeit: ca. 1-3 Werktage

20×4 LCD Display mit I2C Schnittstelle 2004A HD44780

10,99 
Umsatzsteuerbefreit gemäß UStG §19
zzgl. Versand
Lieferzeit: ca. 1-3 Werktage

Programmierarbeiten auf Stundenbasis

29,99 
Umsatzsteuerbefreit gemäß UStG §19
zzgl. Versand
Lieferzeit: keine Lieferzeit