// Dokumentation für diese Bibliothek finden Sie unter:
//
github.com/Stan-Reifel/TinyStepper_28BYJ_48//
//
// Diese Bibliothek erfordert, dass der Schrittmotor mit dem Arduino verbunden ist
// Verwenden der ULN2003-Treiberplatine.
// *************************************************** ************************
#include <TinyStepper_28BYJ_48.h>
#include <Adafruit_NeoPixel.h>
// NEO Pixel Konfiguration
# PIN 0 definieren
#define LEDS_COUNT 5
#define RED strip.Color (255, 0, 0)
#define GREEN strip.Color (0, 255, 0)
#define BLUE strip.Color (0, 0, 255)
#define WHITE strip.Color (255, 255, 255)
// Pinbelegung, es können beliebige digitale Pins verwendet werden
#define MOTOR_IN1_PIN 1
#define MOTOR_IN2_PIN 2
#define MOTOR_IN3_PIN 3
#define MOTOR_IN4_PIN 4
// Schrittmotorobjekt erstellen
TinyStepper_28BYJ_48 stepper;
Adafruit_NeoPixel-Streifen = Adafruit_NeoPixel (LEDS_COUNT, PIN, NEO_GRB + NEO_KHZ800);
void setup () {
// Schrittmotor an seine IO-Pins anschließen und konfigurieren
stepper.connectToPins (MOTOR_IN1_PIN, MOTOR_IN2_PIN, MOTOR_IN3_PIN, MOTOR_IN4_PIN);
// Geschwindigkeit und Beschleunigung des Schrittmotors einstellen
stepper.setSpeedInStepsPerSecond (256);
stepper.setAccelerationInStepsPerSecondPerSecond (512);
strip.begin ();
strip.show (); // Initialisiere alle Pixel auf 'aus'
}
void loop () {
// Den Motor eine Umdrehung vorwärts drehen
stepper.moveRelativeInSteps (410);
für (Byte i = 0; i <20; i ++) {
fadeInOut (0xff, 0x00, 0x00); // rot
}
// 1 Umdrehung rückwärts drehen, dann 1 Sekunde warten
stepper.moveRelativeInSteps (-410);
für (Byte i = 0; i <20; i ++) {
fadeInOut (0x00, 0x00, 0xff); // blau
}
}
void fadeInOut (Byte Rot, Byte Grün, Byte Blau) {
float r, g, b;
für (int k = 0; k <256; k = k + 1) {
r = (k / 256,0) * rot;
g = (k / 256,0) * grün;
b = (k / 256,0) * blau;
setAll (r, g, b);
strip.show ();
Verzögerung (5);
}
für (int k = 255; k> = 0; k = k-2) {
r = (k / 256,0) * rot;
g = (k / 256,0) * grün;
b = (k / 256,0) * blau;
setAll (r, g, b);
strip.show ();
Verzögerung (5);
}
}
void setAll (Byte Rot, Byte Grün, Byte Blau) {
für (int i = 0; i <LEDS_COUNT; i ++) {
strip.setPixelColor (i, strip.Color (rot, grün, blau));
}
strip.show ();
}