//菜单
String SMSTR[]={
"转速", //RPM_转速 0
"加速度", //加速度 1
"减速度", //减速度 2
"反转脉冲", //反转脉冲 3
"步进1正转脉冲", //步进1 正转脉冲 4
"步进2正转脉冲", //步进2 正转脉冲 5
"步进3正转脉冲", //步进3 正转脉冲 6
"步进4正转脉冲", //步进4 正转脉冲 7
};
int SMARG[]={
500, //RPM_转速 0
500, //加速度 1
500, //减速度 2
800, //反转脉冲 3
32000, //步进1 正转脉冲 4
32000, //步进2 正转脉冲 5
32000, //步进3 正转脉冲 6
32000, //步进4 正转脉冲 7
};
#include "A4988.h"
#define MOTOR_STEPS 200 //全步脉冲
#define MICROSTEPPING 16 //细分
#define SM1_DIR 8
#define SM1_STEP 9
#define SM2_DIR 6
#define SM2_STEP 7
#define SM3_DIR 4
#define SM3_STEP 5
#define SM4_DIR 2
#define SM4_STEP 3
A4988 stepper1(MOTOR_STEPS, SM1_DIR, SM1_STEP);
A4988 stepper2(MOTOR_STEPS, SM2_DIR, SM2_STEP);
A4988 stepper3(MOTOR_STEPS, SM3_DIR, SM3_STEP);
A4988 stepper4(MOTOR_STEPS, SM4_DIR, SM4_STEP);
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
//独立按钮
#include <Bounce2.h>
#define Button_ST 18
Bounce2::Button stButton = Bounce2::Button();
void setup() {
// put your setup code here, to run once:
Wire.setSDA(16); //tried GP0-GP1, GP4-GP5
Wire.setSCL(17);
Wire.begin();
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
lcd.init();
lcd.backlight();
lcd.print("HelloWorld");
stepper1.begin(SMARG[0],MICROSTEPPING);
//stepper1.setSpeedProfile(BasicStepperDriver::LINEAR_SPEED, SMARG[1], SMARG[2]);//设置加速度
stepper2.begin(SMARG[0],MICROSTEPPING);
//stepper2.setSpeedProfile(BasicStepperDriver::LINEAR_SPEED, SMARG[1], SMARG[2]);//设置加速度
stepper3.begin(SMARG[0],MICROSTEPPING);
//stepper3.setSpeedProfile(BasicStepperDriver::LINEAR_SPEED, SMARG[1], SMARG[2]);//设置加速度
stepper4.begin(SMARG[0],MICROSTEPPING);
//stepper4.setSpeedProfile(BasicStepperDriver::LINEAR_SPEED, SMARG[1], SMARG[2]);//设置加速度
stButton.attach(Button_ST, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
while(true){
stButton.update();
if(stButton.rose()){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("START");
stepper1.move(3600);
//stepper2.move(3600);
}
}
}