资源简介
esp8266、 esp32、可用的28byj、20byj、24byj五线四相步进电机库文件
代码片段和文件信息
/*
* Stepper2.h - BYJ48 stepper motor library for Wiring/Arduino - Version 0.0.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not write to the Free Software
* Foundation Inc. 51 Franklin St Fifth Floor Boston MA 02110-1301 USA
*
* The circuits can be found at
*
* https://github.com/udivankin/Stepper2
*/
#include “Arduino.h“
#include “Stepper2.h“
const int microsInSecond = 1000L * 1000L;
const int microsInMinute = 60L * microsInSecond;
// Maximum steps per second
const int maxHz = 1000;
// Approx steps count to make a full turn
const int stepsPerFullTurn = 4096;
// Number of steps to make a rev of internal motor
const int numberOfSteps = 64;
// Step matrix
int stepMatrix[8][4] = {
{ LOW LOW LOW HIGH }
{ LOW LOW HIGH HIGH }
{ LOW LOW HIGH LOW }
{ LOW HIGH HIGH LOW }
{ LOW HIGH LOW LOW }
{ HIGH HIGH LOW LOW }
{ HIGH LOW LOW LOW }
{ HIGH LOW LOW HIGH }
};
// Output levels to stop the motor
int allLows[4] = { LOW LOW LOW LOW };
/*
* Constructor for four-pin version
* Sets which wires should control the motor.
*/
Stepper2::Stepper2(int motorPin[4])
{
this->step_number = 0; // which step the motor is on
this->last_step_time = 0; // time stamp in us of the last step taken
// setup the pins on the microcontroller:
for (int i = 0; i < 4; i++) {
this->pin_matrix[i] = motorPin[i];
pinMode(motorPin[i] OUTPUT);
}
}
/*
* Sets the speed in revs per minute
*/
void Stepper2::setSpeed(int rpm)
{
int duration = microsInMinute / stepsPerFullTurn / rpm;
int minDuration = microsInSecond / maxHz;
this->step_duration = duration > minDuration ? duration : minDuration;
}
/*
* Sets the speed in revs per minute
*/
void Stepper2::setDirection(int direction)
{
this->direction = direction;
}
/*
* Write pin state to output
*/
void Stepper2::writeStep(int outArray[4]){
for (int i = 0; i < 4; i++) {
digitalWrite(this->pin_matrix[i] outArray[i]);
}
}
/*
* Moves the motor stepsToMove steps.
*/
void Stepper2::step(int stepsToMove)
{
int stepsLeft = abs(stepsToMove); // how many steps to take
// Adjust stepsToMove accrodign to direction
if (this->direction == 1) {
stepsToMove = -stepsToMove;
}
// decrement the number of steps moving one step each time
while (stepsLeft > 0) {
unsigned long now = micros();
// move only if the appropriate delay has passed
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-03-06 19:42 Stepper2-master\
文件 966 2017-03-06 19:42 Stepper2-master\README.adoc
目录 0 2017-03-06 19:42 Stepper2-master\examples\
目录 0 2017-03-06 19:42 Stepper2-master\examples\Stepper2_oneTurn\
文件 561 2017-03-06 19:42 Stepper2-master\examples\Stepper2_oneTurn\stepper_oneRevolution.ino
文件 664 2017-03-06 19:42 Stepper2-master\keywords.txt
文件 310 2017-03-06 19:42 Stepper2-master\library.properties
目录 0 2017-03-06 19:42 Stepper2-master\src\
文件 4364 2017-03-06 19:42 Stepper2-master\src\Stepper2.cpp
文件 1995 2017-03-06 19:42 Stepper2-master\src\Stepper2.h
- 上一篇:数据结构课程设计——地铁建设问题
- 下一篇:STM32多路数据采集源代码
相关资源
- Arduino uno+esp8266+onenet+dht11温湿度传感器
- 安信可ESP-12S WIFI文档
- Arduino通过ESP8266模块使用HTTP协议连接
- esp8266控制步进电机.txt
- 28BYJ-48步进电机改2相4线
- ESp8266驱动
- arduino烧录esp8266程序
- 51单片机驱动WiFi模块ESP8266模块的代码
- esp8266 探测MAC地址,串口输出.环境
- esp8266 连接阿里物理网平台远程控制
- ESP8266的TCP服务器连接错误解决办法
- ESP8266(arduino)连接阿里云物联网平台
- Esp8266_Wifi原理图
- nodemcu固件2018-06-25
- ESP8266通信源码+继电器控制
- esp8266连接手机热点,可通过阿里云实
- ESP8266串口输入字符串,同时用0.96寸
- ESP8266AT指令连接云平台
- esp8266-RTOS SDK IPV6
- STM32+8266+连接云平台源码.zip
- 51单片机程序.zip
- STM32F103C8T6使用ULN2003模块控制28BYJ-48电
- Mixly 的 ESP8266 库
- ESP8266连接ONENET平台传输数据------笔记
- ESP8266与上位机通信代码
- ESP32开发板原理图ESP-WROVER-KIT.pdf
- 米思齐esp8266wifi库.zip
- C51_ESP8266_rc522.rar
- esp8266_modules_libraries esp8266相关模组的
- ESP8266 PWM源文件
评论
共有 条评论