// Raspberry Pi Pico + Stepper Motor Example
#include <Bounce2.h>
#include <Stepper.h>
const int stepsPerRevolution = 2038; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 21, 22, 26, 27);
int tst1 = 6;
int tst2 = 1;
int tst3 = 5;
Bounce T1 = Bounce();
Bounce T2 = Bounce();
Bounce T3 = Bounce();
void setup() {
// set the speed at 60 rpm:
T1.attach(tst1, INPUT);
T1.interval(25);
T2.attach(tst2, INPUT);
T2.interval(25);
T3.attach(tst3, INPUT);
T3.interval(25);
//test program
if (int i = 0){
T1.update();
if(T1.fell() && i<2){
myStepper.setSpeed(5);
myStepper.step(200);
delay(1000);
i++;
}
}
if(int i = 0){
T2.update();
if(T2.fell() && i<2)
{
myStepper.setSpeed(10);
myStepper.step(-200);
delay(1000);
i++;
}
}
// initialize the serial port:
Serial.begin(115200);
}
void loop() {
//test program
myStepper.setSpeed(15);
T1.update();
if(T1.fell()){
myStepper.step(200);
delay(1000);
myStepper.step(-200);
}
T2.update();
if(T2.fell())
{
myStepper.step(-200);
delay(1000);
myStepper.step(200);
}
T3.update();
if(T3.fell())
{
myStepper.step(200);
delay(1000);
myStepper.step(-200);
}
delay(500);
}