// defines pins numbers
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
////stepper
const int dirPin = 3;
const int stepPin = 4;
const int enPin = 5;
const int switchOne = 8;
const int switchTwo = 9;
int switchOneState = 0;
int switchTwoState = 0;
////direction ccw or cw
int ledPinGreen = 10; //cw
int ledPinRed = 11; //ccw
////LCD
char array1[] = " BADBASSFISHING";
char array2[] = " FFS Stepper";
char array3[] = " Jose Cisneros";
char array4[] = " IVY TECH PROJECT";
char array5[] = " System Running ";
char array6[] = "Motor Pos:";
char array7[] = "CW";
char array8[] = "CCW";
LiquidCrystal_I2C lcd(0x27, 20, 4);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
/////LCD
lcd.init();
lcd.backlight();
lcd.print(array1);
lcd.setCursor(0,1);
lcd.print(array2);
lcd.setCursor(0,2);
lcd.print(array3);
lcd.setCursor(0,3);
lcd.print(array4);
delay(4000);
/////SYSTEM RUNNIN
lcd.clear();
lcd.init();
lcd.backlight();
lcd.print(array1);
lcd.setCursor(0,1);
lcd.print(array5);
lcd.setCursor(0,2);
lcd.print(array6);
/////Stepper
Serial.begin(9600);
pinMode(switchOne, INPUT_PULLUP);
pinMode(switchTwo, INPUT_PULLUP);
switchOneState = HIGH;//default state for input pullup
switchTwoState = HIGH;
///// Sets the two pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW);
/////light direction
pinMode(ledPinGreen, OUTPUT);
pinMode(ledPinRed, OUTPUT);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
//debounce switches by reading every 50 ms
static unsigned long lastReading = 0;
if (millis() - lastReading >= 50)
{
lastReading = millis();
switchOneState = digitalRead(switchOne);
switchTwoState = digitalRead(switchTwo);
}
/////CCW
if (switchOneState == LOW) //button is pressed
{
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(50);
digitalWrite(stepPin, LOW);
delayMicroseconds(50);
digitalWrite(ledPinRed, HIGH);
digitalWrite(ledPinGreen,LOW);
}
/////CW
if (switchTwoState == LOW)
{
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(50);
digitalWrite(stepPin, LOW);
delayMicroseconds(50);
digitalWrite(ledPinGreen, HIGH);
digitalWrite(ledPinRed,LOW);
}
}
this is where im at with the program so far. My issue is when trying to input the cw or ccw next to the motor pos: it doesnt allow me to rotate the motor anymore. I had the coding under the if's statements under the led description but, it would just make the motor hum and do nothing. I am new to arduino programming. But I have had c++ programming already. Could anyone help me out and see what i could do better to get me going? thank you for your time and patience