Im building a replica Crane game using my Arduino mega 2560 for my BS in Electronics. I think i have most of the code down but when i connect everything up to my motor controller nothing happens. Can someone look at my code and let me know if I did something wrong. other sites i have tried havent really offered any help.
#include <LiquidCrystal.h>
// This code is for CapStone Project Replica Crane Game.
//======================================================================================//
// inputs for Joystick
//up
int joyup = 13;
//down
int joydown = 12;
//left
int joyleft = 14;
//right
int joyright = 15;
//======================================================================================//
//Inputs for Buttons
// Start Button
int startb = 9;
// Drop Claw Button
int dropb = 8;
// Close Claw Button
int closeb = 7;
// Raise Claw
int raiseb = 6;
//======================================================================================//
// Motor Control Pins
int EnablePin1 = 30;
int EnablePin2 = 31;
int EnablePin3 = 32;
int EnablePin4 = 33;
int Testpin = A0;
//======================================================================================//
// X axis Motor Forward
int MotorUp = 22;
// X Axis Motor BReverse
int MotorDown = 23;
// Y Axis Motor Forward
int MotorLeft = 24;
// Y Axis Motor Reverse
int MotorRight = 25;
// Claw Lower Motor
int ClawDown = 26;
// Claw Raise Motor
int ClawUp = 27;
// HIGH will Close Claw, When LOW Claw will release
int Claw = 28;
//======================================================================================//
//LCD Screen Pins
LiquidCrystal lcd(11, 10, 5, 4, 3, 2);
//======================================================================================//
// Pin Set up
void setup(){
// Setup Input Pins
pinMode(joyup, INPUT);
pinMode(joydown, INPUT);
pinMode(joyleft, INPUT);
pinMode(joyright, INPUT);
pinMode(startb, INPUT);
pinMode(dropb, INPUT);
pinMode(closeb, INPUT);
pinMode(raiseb, INPUT);
//======================================================================================//
// Enable Pins for Motor Control
pinMode(EnablePin1, OUTPUT);
pinMode(EnablePin2, OUTPUT);
pinMode(EnablePin3, OUTPUT);
pinMode(EnablePin4, OUTPUT);
pinMode(Testpin, OUTPUT);
//======================================================================================//
// Setup Out Pins
pinMode(MotorUp, OUTPUT);
pinMode(MotorDown, OUTPUT);
pinMode(MotorLeft, OUTPUT);
pinMode(MotorRight, OUTPUT);
pinMode(ClawDown, OUTPUT);
pinMode(ClawUp, OUTPUT);
pinMode(Claw, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("Would You like");
delay(2000);
lcd.begin(16,2);
lcd.print("to Play?");
}
//======================================================================================//
//Input Command Calls FOR HIGH
void detect(){
if (startb == HIGH){
lcd.begin(16, 2);
//Start Msg
lcd.print("Starting Game");
}
// MOTOR UP
if (joyup == HIGH){
EnablePin1 = HIGH;
MotorDown = LOW;
MotorUp = HIGH;
lcd.begin(16, 2);
lcd.print("Up, Moving UP");
}
// MOTOR DOWN
if (joydown == HIGH){
EnablePin1 = HIGH;
MotorUp = LOW;
MotorDown = HIGH;
lcd.begin(16, 2);
lcd.print("Down, Moving Down");
}
// MOTOR LEFT
if (joyleft == HIGH){
EnablePin2 = HIGH;
MotorRight = LOW;
MotorLeft = HIGH;
lcd.begin(16, 2);
lcd.print("Left, Moving Left");
}
// MOTOR RIGHT
if (joyright == HIGH){
EnablePin2 = HIGH;
MotorLeft = LOW;
MotorRight = HIGH;
lcd.begin(16, 2);
lcd.print("Right, Moving Right");
}
// DROP CLAW
if (dropb == HIGH){
EnablePin3 = HIGH;
ClawUp = LOW;
ClawDown = HIGH;
lcd.begin(16, 2);
lcd.print("Claw, Lowering Claw");
}
// RAISE CLAW
if (raiseb == HIGH){
EnablePin3 = HIGH;
ClawDown = LOW;
ClawUp = HIGH;
lcd.begin(16, 2);
lcd.print("Claw, Raising Claw");
}
// CLOSE CLAW
if (closeb == HIGH){
EnablePin4 = HIGH;
Claw = HIGH;
lcd.begin(16, 2);
lcd.print("Claw, Closing");
}
//======================================================================================//
// Dectect Commands for LOW
// MOTOR UP
if (joyup == LOW){
EnablePin1 = LOW;
MotorUp = LOW;
}
// MOTOR DOWN
if (joydown == LOW){
EnablePin1 = LOW;
MotorDown = LOW;
}
// MOTOR LEFT
if (joyleft == LOW){
EnablePin2 = LOW;
MotorLeft = LOW;
}
// MOTOR RIGHT
if (joyright == LOW){
EnablePin2 = LOW;
MotorRight = LOW;
}
// DROP CLAW
if (dropb == LOW){
EnablePin3 = LOW;
ClawDown = LOW;
}
// RAISE CLAW
if (raiseb == LOW){
EnablePin3 = LOW;
ClawUp = LOW;
}
// CLOSE CLAW
if (closeb == LOW){
EnablePin4 = LOW;
Claw = LOW;
}
}
//======================================================================================//
// Automated Claw Reset when Button 3 is Pressed
// Will Return Claw back to Start Position
void loop() {
detect;
Testpin = HIGH;
if (closeb == HIGH);
{
lcd.begin(16, 2);
lcd.print("Returning Claw With Prize");
EnablePin3 = HIGH;
ClawUp = HIGH;
delay(2000);
EnablePin3 = LOW;
ClawUp = LOW;
delay(2000);
EnablePin2 = HIGH;
MotorLeft = HIGH;
delay(5000);
EnablePin2 = LOW;
MotorLeft = LOW;
EnablePin1 = HIGH;
MotorDown = HIGH;
delay(5000);
EnablePin1 = LOW;
MotorDown = LOW;
EnablePin4 = LOW;
Claw = LOW;
lcd.begin(16, 2);
lcd.print("Enjoy Your Prize");
}
}