Pages: [1]   Go Down
Author Topic: claw machine mega controled  (Read 482 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello guys im new to the arduino and im trying to control one of those old claw machines that you would see at an arcade place or in some resturants with and arduino! ive got some code wrote for it so far and would like to know your opinions on how my programming is and maybe some tips for improvement. ill post the code ive got so far below. some info on the machine it has about 14 inputs and about 10 outputs in you count each motor direct as a diffrent output. all the inputs im referring to in the program are are basic limit switches with no or nc set of contacts even the joy stick buttons except for the the  drop claw button , and the dollar receiving and the coin receiving inputs. there is also a 2 digit 7 segment display that i will eventually need to control as well for counting down 30 seconds for each turn. so far i have just basic motor controls, i do not have the money receiving yet because im not sure how the dollar mech works and havent checked the voltage signals for the mechanical coin input. thanks for you time and would appreciate your input.


 // constants won't change. they're used here to
// set pin numbers
// bridge limits and claw limits
const int lsfwrdPin = 22;
const int lsdwnPin = 23;
const int lsleftPin = 24;
const int lsrightPin = 25;
const int lsclawtensionPin = 26;
const int lsclawdoorPin = 27;

// joy movment buttons
const int joyfwrdPin = 28;
const int joydwnPin = 29;
const int joyleftPin = 30;
const int joyrightPin = 31;
// dorp claw
const int dropclawbuttonPin = 32;
// motors controled
const int motor1fwrdPin = 34;
const int motor1dwnPin = 35;
const int motor2rightPin = 36;
const int motor2leftPin = 37;
// claw motor
const int motor3upPin = 38;
const int motor3dwnPin = 39;


// variables will change
int lsfwrdState = 0;
int lsdwnState = 1;
int lsleftState = 2;
int lsrightState = 3;
int joyfwrdState = 4;
int joydwnState = 5;
int joyleftState = 6;
int joyrightState = 7;
int lsclawtensionState = 8;
int lsclawdoorState = 9;
int dropclawbuttonState = 10;
int motor3dwnState = 11;
int motor3upState = 12;


void setup(){
  pinMode(motor1fwrdPin, OUTPUT);
  pinMode(motor1dwnPin, OUTPUT);
  pinMode(motor2rightPin, OUTPUT);
  pinMode(motor2leftPin, OUTPUT);
  pinMode(motor3upPin, OUTPUT);
  pinMode(motor3dwnPin, OUTPUT);
 
  pinMode(lsfwrdPin, INPUT);
  pinMode(lsdwnPin, INPUT);
  pinMode(lsleftPin, INPUT);
  pinMode(lsdwnPin, INPUT);
  pinMode(joyfwrdPin, INPUT);
  pinMode(joydwnPin, INPUT);
  pinMode(joyleftPin, INPUT);
  pinMode(joyrightPin, INPUT);
  pinMode(lsclawtensionPin, INPUT);
  pinMode(lsclawdoorPin, INPUT);
  pinMode(dropclawbuttonPin, INPUT);
}

void loop(){
  // reads the state of buttons
  lsfwrdState = digitalRead(lsfwrdPin);
  lsdwnState = digitalRead(lsdwnPin);
  lsleftState = digitalRead(lsleftPin);
  lsrightState = digitalRead(lsrightPin);
  joyfwrdState = digitalRead(joyfwrdPin);
  joydwnState = digitalRead(joydwnPin);
  joyleftState = digitalRead(joyleftPin);
  joyrightState = digitalRead(joyrightPin);
  lsclawtensionState = digitalRead(lsclawtensionPin);
  lsclawdoorState = digitalRead(lsclawdoorPin);
  dropclawbuttonState = digitalRead(dropclawbuttonPin);
  motor3dwnState = digitalRead(motor3dwnPin);
  motor3upState = digitalRead(motor3upPin);
 
  // check if joy button is pressed(high) and limit
  // switch is off(low) if true motor is on(high)
 
  // fwrd motor contorl
  if (lsfwrdState == LOW && joyfwrdState == HIGH) {

    digitalWrite(motor1fwrdPin, HIGH);
  }
  else{
    digitalWrite(motor1fwrdPin, LOW);
  }
 
 // back motor control
  if (lsdwnState == LOW && joydwnState == HIGH){
   digitalWrite(motor1dwnPin, HIGH);
  }
 else{
  digitalWrite(motor1dwnPin, LOW);
 }
 // left motor control
 if (lsleftState == LOW && joyleftState == HIGH){
   digitalWrite(motor2leftPin, HIGH);
 }
 else{
   digitalWrite(motor2leftPin, LOW);
 }
 // right motor control
 if (lsrightState == LOW&& joyrightState == HIGH){
   digitalWrite(motor2rightPin, HIGH);
 }
 else{ digitalWrite(motor2rightPin, LOW);
 }
 // the following commands under are for claw functions 
 if (dropclawbuttonState == HIGH && ){
   digitalWrite(dropclawbuttonPin, HIGH);
 }
     else{ digitalWrite(dropclawbuttonPin, LOW);
     }

 if (dropclawbuttonState == HIGH && //need code for the closed claw reaching its home postion where it drops the prize needs to go here, not finished
 // i was thinking that i could move it foward till limit is reach and the move side ways till limit is reached, which would put the claw at the prize drop
   if (lsclawtensionState == LOW && dropclawbuttonState == HIGH){
  digitalWrite(motor3dwnPin, HIGH);
 }
else{ digitalWrite(motor3dwnPin, LOW);
}

//clawtension high needs to latch m3up until clawdoorlimit is high
if (lsclawtensionState == HIGH){
  delay(500)
  digitalWrite(motor3upPin, HIGH);
}
if (motor3upState == HIGH){
  digitalWrite(motor3upPin, HIGH);
}
  if (lsclawdoorState == HIGH){
    digitalWrite(motor3upPin, LOW);
  }
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26496
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is your shift key broken?
Please read the sticky thread at the top of this section.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: