Нужна помощь с кодом под Arduino
И тут наткнулся на то, как человек сделал автоматизацию стола. Но вот закавыка - он использовал другую плату управления.
Я, к сожалению, совсем не программер, и попытка самому 'прописать' кое-что из примеров 'не вышла'.
Может кто-то сможет помочь с правкой кода под запуск на ArduinoUno?
________________________________________
Исходный код под плату Adafruit:
________________________________________
#include
#include
#include 'utility/Adafruit_MS_PWMServoDriver.h'
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
void setup() {
Serial.begin(9600); // open serial port
AFMS.begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(1); // 1 rpm
myMotor->step(1, FORWARD, MICROSTEP); // take a step to initialize position
delay(250); // settle mechanics for 250 ms
myMotor->release(); // turn off current
}
void loop() {
static int counter = 0;
if(Serial.available()>0) // is there any unread serial data?
{
char ch = Serial.read(); // read a character from the serial port
Serial.print('echo');
Serial.println(ch); // echo back so that it is displayed in DAVID debug console
if (ch == '2') // is it the character for the number 2?
{
counter = counter + 1; // increment the scan count
myMotor->step(10, FORWARD, MICROSTEP); // take a step
delay(250); // settle mechanics for 250 ms
myMotor->release(); // turn off current
if (counter == 16) // we have performed a full rotation
{
counter = 0; // reset for next scan
}
else
{
Serial.println('S'); // Tell DAVID to do another Scan
}
}
} // end Serial.available
}
_________________________________________
А вот что я 'наваял' (нерабочее)...
_________________________________________
#include
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myMotor (stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// initialize the serial port:
Serial.begin(9600); // open serial port
// myMotor->begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(1); // 1 rpm
myMotor->step(10, FORWARD, MICROSTEP); // take a step to initialize position
delay(250); // settle mechanics for 250 ms
myMotor->release(); // turn off current
}
void loop() {
static int counter = 0;
if(Serial.available()>0) // is there any unread serial data?
{
char ch = Serial.read(); // read a character from the serial port
Serial.print('echo');
Serial.println(ch); // echo back so that it is displayed in DAVID debug console
if (ch == '2') // is it the character for the number 2?
{
counter = counter + 1; // increment the scan count
myMotor->step(10, FORWARD, MICROSTEP); // take a step
delay(250); // settle mechanics for 250 ms
myMotor->release(); // turn off current
if (counter == 16) // we have performed a full rotation
{
counter = 0; // reset for next scan
}
else
{
Serial.println('S'); // Tell DAVID to do another Scan
}
}
} // end Serial.available
}
Популярные вопросы
Какие принтеры купить вместо Anet a8?
Напечатанные шестерни быстро стёрлись в работе
Программа для 3D проектирования
Пр...
Комментарии и вопросы
Хвост съёмный для печати
Рама здорового человека :)
Спасибо за оценку!
Здравствуйте, у меня перестала...
Доброго времени суток.Неожидан...
Всем доброго дня. Вчера кинул...
Мне нужно напечатать модель эт...