Below is an updated version of my projects code, I've used a combination of online examples to get the project working at its minimal viable outcome. Although not finalised as I still need to implement some of the messages in the code I will be using this as the bones of the project.
// Include the required Arduino libraries:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <Stepper.h>
//Based on the MAX7219 LED Matrix Display Arduino Tutorial (4 Examples) (makerguides.com) example code:
// Define hardware type, size, and output pins:
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 3
//Initialise new class for MD_Parola, assigning hardware SPI connections:
MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
//Variable for the number of steps per revolution.
const int stepsPerRevolution = 200;
//Initialise the stepper motor using the Stepper class assigning it with its pins:
Stepper stepperMotor(stepsPerRevolution, 8, 9, 10, 12);
//Variable to hold the number of steps
int stepCounter = 0;
//CODE SET UP
void setup() {
//Start the serial port (for keeping track of counting the steps)
Serial.begin(9600);
//SET UP FOR THE LED MATRIX
ledMatrix.begin();
// Control the brightness
ledMatrix.setIntensity(0);
// Clears the display
ledMatrix.displayClear();
}
//REPEATING CODE
void loop() {
// Code based on the One Step At A Time example: https://www.arduino.cc/en/Tutorial/LibraryExamples/StepperOneStepAtATime
//Make the stepper take 1 step at a time:
stepperMotor.step(1);
//Serial print
Serial.print("Step Count:");
Serial.println(stepCounter);
//Incrementation to ensure steps go up
stepCounter++;
//Delay between steps
delay(500);
//if statement which communicates between the stepper and the ledmatrix
if(stepCounter == 20)
{
ledMatrix.displayText("Scrolling text", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}
delay(1000);
if(stepCounter == 100)
{
ledMatrix.displayText("Another Text", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}
}
Next Steps:
+ Finalise the text, test that the timing works for each method and the movement of the stepper.
+ Ensure that the cranes platform is stable and the cranes do not fall over when turning
+ Work on getting more than one stepper working at a time
+ Document and reupload youtube video for this.
Comments