当前位置:网站首页>Arduino+a4988 control stepper motor
Arduino+a4988 control stepper motor
2022-07-05 08:28:00 【Sharing master】
* foot 6(-en) Low level refers to starting motor (enable), It seems that you can not answer , Tried to run the same . But if you want to control the starting and closing of the motor, you still need to use
* foot 4(-dir) Control the direction with high and low levels .
* foot 5(-step) Drive the motor to rotate with high and low levels . Note the microsecond value of the waiting interval , If it is too fast, it will cause the motor to make a sound and do not rotate .
const int stepPin = 12; //D6
const int dirPin = 14; //D5
const int enable = 16; //D0
const int key1 = 5; //D1 Forward 0.5
const int key2 = 4; //D2 back off 0.5
const int key3 = 0; //D3 Back to 0
int ButtonState = HIGH;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enable,OUTPUT);
pinMode(key1,INPUT_PULLUP);
pinMode(key2,INPUT_PULLUP);
pinMode(key3,INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Sensor Test");
Serial.println("");
}
void step(boolean dir, int steps)
{
digitalWrite(enable, LOW);//enable
digitalWrite(dirPin, dir); //dir=1
delay(50);
for (int i = 0; i < steps; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepPin, LOW);
delayMicroseconds(800);
}
digitalWrite(enable, HIGH);//disable
}
void addone() // Forward 0.5
{
int reading = digitalRead(key1);
if (reading != ButtonState) {
delayMicroseconds(500);
reading = digitalRead(key1);
if (reading == LOW) {
step(true, 200); delay(500);
Serial.println("---------------- Forward --------------------");
}
}
}
void minone() // back off 0.5
{
int reading = digitalRead(key2);
if (reading != ButtonState) {
delayMicroseconds(500);
reading = digitalRead(key2);
if (reading == LOW) {
step(false, 200); delay(500);
Serial.println("---------------- back off --------------------");
}
}
}
void zreoone() // Back to 0
{
int reading = digitalRead(key3);
if (reading != ButtonState) {
delayMicroseconds(500);
reading = digitalRead(key3);
if (reading == LOW) {
for (int i = 0; i < 2; i++) {
step(false, 500); delay(500);
delayMicroseconds(800);
Serial.println("----------------KEY3--------------------");
}
}
}
}
void estkey() // Key judgment
{
Serial.println("----------------OK--------------------");
}
void loop()
{
addone();
minone();
zreoone();
}
Reference article Arduino+A4988+ Stepper motor Press the key to shake off
边栏推荐
- 实例007:copy 将一个列表的数据复制到另一个列表中。
- Wifi-802.11 negotiation rate table
- Naming rules for FreeRTOS
- Weidongshan Internet of things learning lesson 1
- Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
- Hardware and software solution of FPGA key chattering elimination
- UE像素流,来颗“减肥药”吧!
- [tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
- 剑指 Offer 05. 替换空格
- UE pixel stream, come to a "diet pill"!
猜你喜欢
剑指 Offer 09. 用两个栈实现队列
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement
STM32---ADC
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
MHA High available Cluster for MySQL
Tailq of linked list
每日一题——输入一个日期,输出它是该年的第几天
Ble encryption details
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase
随机推荐
Void* C is a carrier for realizing polymorphism
Adaptive filter
Stm32--- systick timer
Live555 push RTSP audio and video stream summary (I) cross compilation
Working principle and type selection of common mode inductor
STM32 single chip microcomputer - external interrupt
Classic application of MOS transistor circuit design (2) - switch circuit design
Design a clock frequency division circuit that can be switched arbitrarily
Briefly talk about the identification protocol of mobile port -bc1.2
实例009:暂停一秒输出
How to write cover letter?
STM32 virtualization environment of QEMU
Sword finger offer 06 Print linked list from end to end
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Vofa+ software usage record
NTC thermistor application - temperature measurement
Take you to understand the working principle of lithium battery protection board
MATLAB小技巧(28)模糊综合评价
Naming rules for FreeRTOS
实例010:给人看的时间