#include <SPI.h>
#include <Controllino.h>
const int t7 = CONTROLLINO_D1; //set t7 (DISABLE IN) to D1 pin of Controllino (this can be changed if wiring on PLC is different); 5V = start spinning 0V= stop spinning
const int t8 = CONTROLLINO_D4; //set t8 (DIR IN) to D4 pin of Controllino; 5V = CW movement
const int t9 = CONTROLLINO_D2; //set t9 (STEP IN) to D2 pin of Controllino; 5V = CCW movement
char in; //input to decide what the motor should do
/*
- INPUT GUIDE
- a = CW motion
- b = CCW motion
- c = stop
- SPEED IS SET ON THE DRIVE
- REFER TO P5000 MANUAL FOR INFORMATION
*/
void setup() {
// put your setup code here, to run once:
pinMode(t7, OUTPUT); //set pin as an output
pinMode(t8, OUTPUT); //set pin as an output
pinMode(t9, OUTPUT); //set pin as an output
Serial.begin(9600); //start serial communication
Serial.println("We are in VCO mode \n Guide to input \n a = CW motion \n b = CCW motion \n c = Stop"); //basic instruction prior to code start printed onto Serial Monitor
}
void loop() {
// put your main code here, to run repeatedly:
in = Serial.read(); //take input through Serial Monitor
if(isAlpha(in)) //check if there is an input and input is a char
{
Serial.println(in); //feedback on what you entered
Serial.println("START OF CODE"); //feedback on this is start of code
}
if(in == 'a') //check if input is a
{
Serial.println("running CW..."); //feedback; shown on Serial Monitor
digitalWrite(t9, LOW); //Set pin to ~0V; reason for setting this is to be double sure the pin is not set to HIGH
delay(1000);
digitalWrite(t7, HIGH); //Set pin to ~5V
delay(1000);
digitalWrite(t8, HIGH); //Set pin to ~5V
delay(1000);
}
if(in == 'b') //check if input is b
{
Serial.println("running CCW..."); //feedback; shown on Serial Monitor
digitalWrite(t8, LOW); //Set pin to ~0V
digitalWrite(t7, HIGH); //Set pin to ~5V
digitalWrite(t9, HIGH); //Set pin to ~5V
}
if(in == 'c') //check if input is c
{
Serial.println("stopping...");
digitalWrite(t7, LOW);
digitalWrite(t8, LOW);
digitalWrite(t9, LOW);
}
}
Once I type 'a' the motor rotates in counter clockwise, but I do not want them to run forever. I can stop the motor when I type 'c'. However, using the delay function, I do want to make them run only for few seconds. When I put delay functions in the above, it does not give me any error nor any changes in the motor.
Can someone please help me?
Thank you