// La documentación de esta biblioteca se puede encontrar en:
//
github.com/Stan-Reifel/TinyStepper_28BYJ_48//
//
// Esta biblioteca requiere que el motor paso a paso esté conectado al Arduino
// utilizando la placa de controlador ULN2003.
// ************************************************** ************************
#include <TinyStepper_28BYJ_48.h>
#include <Adafruit_NeoPixel.h>
// Configuración de NEO Pixel
#define PIN 0
#define LEDS_COUNT 5
#define la tira ROJA.Color (255, 0, 0)
#defina la tira VERDE Color (0, 255, 0)
#define BLUE strip.Color (0, 0, 255)
#define la tira BLANCA Color (255, 255, 255)
// asignaciones de pin, se puede usar cualquier pin digital
#define MOTOR_IN1_PIN 1
#define MOTOR_IN2_PIN 2
#define MOTOR_IN3_PIN 3
#define MOTOR_IN4_PIN 4
// crea el objeto motor paso a paso
TinyStepper_28BYJ_48 paso a paso;
Tira de Adafruit_NeoPixel = Adafruit_NeoPixel (LEDS_COUNT, PIN, NEO_GRB + NEO_KHZ800);
configuración nula () {
// conecta y configura el motor paso a paso a sus pines IO
stepper.connectToPins (MOTOR_IN1_PIN, MOTOR_IN2_PIN, MOTOR_IN3_PIN, MOTOR_IN4_PIN);
// establece la velocidad y las tasas de aceleración para el motor paso a paso
stepper.setSpeedInStepsPerSecond (256);
stepper.setAccelerationInStepsPerSecondPerSecond (512);
strip.begin ();
strip.show (); // Inicializa todos los píxeles a 'apagado'
}
bucle vacío () {
// Gire el motor hacia adelante una revolución
stepper.moveRelativeInSteps (410);
para (byte i = 0; i <20; i ++) {
fadeInOut (0xff, 0x00, 0x00); // rojo
}
// gira hacia atrás 1 rotación, luego espera 1 segundo
stepper.moveRelativeInSteps (-410);
para (byte i = 0; i <20; i ++) {
fadeInOut (0x00, 0x00, 0xff); // azul
}
}
vacío fadeInOut (byte rojo, byte verde, byte azul) {
flotador r, g, b;
para (int k = 0; k <256; k = k + 1) {
r = (k / 256.0) * rojo;
g = (k / 256.0) * verde;
b = (k / 256.0) * azul;
setAll (r, g, b);
strip.show ();
retraso (5);
}
para (int k = 255; k> = 0; k = k-2) {
r = (k / 256.0) * rojo;
g = (k / 256.0) * verde;
b = (k / 256.0) * azul;
setAll (r, g, b);
strip.show ();
retraso (5);
}
}
conjunto vacío (byte rojo, byte verde, byte azul) {
para (int i = 0; i <LEDS_COUNT; i ++) {
strip.setPixelColor (i, strip.Color (rojo, verde, azul));
}
strip.show ();
}