Металл2024 Реклама
Метобр2024 Реклама

Нужна помощь с кодом под Arduino

OBN_RacerMan
Идет загрузка
Загрузка
10.08.2019
743
10
Вопросы и ответы
Валяется у меня 3D сканер Циклоп. Стол от него я использую для нормального 3D сканера (напечатал проставку в прошипник, чтобы руками поворачивать).

И тут наткнулся на то, как человек сделал автоматизацию стола. Но вот закавыка - он использовал другую плату управления.

Я, к сожалению, совсем не программер, и попытка самому 'прописать' кое-что из примеров 'не вышла'.

Может кто-то сможет помочь с правкой кода под запуск на 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

}
Ответы на вопросы
Кремень КБ Реклама
Кремень КМ Реклама