c_cpp Arduino的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Arduino的相关的知识,希望对你有一定的参考价值。

#include <AccelStepper.h>

const int stepsPerRevolution = 50; // change this to fit the number of steps per revolution for your motor
const int cm = stepsPerRevolution * 4.935; // number of steps required to move 1cm

const int button1Pin = 10;
const int button2Pin = 11;
const int button3Pin = 12;

int limitSwitch = 1;
int button2State = 1;
int button3State = 1;

// see http://www.airspayce.com/mikem/arduino/AccelStepper/index.html
AccelStepper stepper(AccelStepper::FULL4WIRE,5,6,7,8); // defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup() {
  // serial settings
  Serial.begin(9600); // set up Serial library at 9600 bps
  Serial.println("Stepper test!");
  
  // motor settings
  stepper.setMaxSpeed(220);
  stepper.setAcceleration(1000);
  stepper.setCurrentPosition(0);
  
  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);
  pinMode(button3Pin, INPUT_PULLUP);
//  attachInterrupt(0, limitStop, CHANGE);
}

void loop() {
  limitSwitch = digitalRead(button1Pin);
  Serial.println(limitSwitch);  
  if (limitSwitch == 0) {
    return;
  }
  
  button2State = digitalRead(button2Pin);
  Serial.println(button2State);  
  if (button2State == 0) {    
    // move foreward  
    stepper.moveTo(stepper.currentPosition() + 1);
  }
  
  button3State = digitalRead(button3Pin);
  Serial.println(button3State);  
  if (button3State == 0) {
    // move backward
    stepper.moveTo(stepper.currentPosition() - 1);  
  }
  
  stepper.run();
}

/*
void limitStop() {
  stepper.stop();
  stepper.setCurrentPosition (0);
}
*/

以上是关于c_cpp Arduino的的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp Arduino.ino

c_cpp Arduino声纳距离

c_cpp 使用Arduino的现代能量计

c_cpp 与Pebble通信的Arduino代码

c_cpp Arduino地图价值 - 来自https://www.arduino.cc/en/Reference/Map

c_cpp arduino101-balancing.ino