I am very new to coding, and I can't seem to diagnose what is wrong with my code. I have read a number of posts on this same subject but can't seem to figure out what I am doing wrong.
Any assistance is appreciated.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// 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, 2);
#include <Conceptinetics.h>
#define DMX_SLAVE_CHANNELS 1
// Configure a DMX slave controller
DMX_Slave dmx_slave ( DMX_SLAVE_CHANNELS );
// current location of motor
#define C
// DMX value in
#define X
// how far to move the motor
#define M
void setup() {
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
myMotor->setSpeed(10); // 10 rpm
//Enable DMX
dmx_slave.enable ();
// Set starting address
dmx_slave.setStartAddress (1);
//set initial DMX value to 0
X = 0
// set inital movment value to 0
M = 0
// set current position to 0
C = 0
}
void loop()
{
int X;
int M;
int C;
X = dmx_slave.getChannelValue (1); //get current DMX value from console
if (C < X) // if the DMX value is greater than the current position
{
M = (X - C); // set travel distance to difference between DMX value and currrent position
myMotor->step(M, FORWARD, SINGLE); //move the stepper motor forward
C = (C + M); // assign new current position value
}
else if (C > X) // if the DMX value is less than the current position
{
M = (C - X); // set travel distance to difference between DMX value and currrent position
myMotor->step(M, BACKWARD, SINGLE); //move the stepper motor backward
C = (C - M); // assign new current position value
}
else
{
M = (0); //set the travel distance to 0
myMotor->step(M, BACKWARD, SINGLE); // do not move the motor
}
}