Advertisement
Guest User

Untitled

a guest
May 5th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int Blank = 0;
  2. //Begin Pin Designation
  3. int STBY = 11; //standby
  4. int PWMA = 10; //Speed control
  5.  
  6. // {Pin1, Pin2, Position}
  7. int motorPins[5][3] = {{13, 12, 0}, {8, 9, 0}, {7, 6, 0}, {5, 6, 0}, {2, 3, 0}};
  8.  
  9. int inByte = Serial.read();
  10.  
  11. //End Pin Designation
  12.  
  13. //Define Pin Designations for Fingers
  14. void setup() {
  15.     pinMode(STBY, OUTPUT);
  16.     pinMode(PWMA, OUTPUT);
  17.     for (int i = 0; i  < 5; i++){
  18.         pinMode(motorPins[i][0], OUTPUT);
  19.         pinMode(motorPins[i][1], OUTPUT);
  20.         move(i, 255, 1, true);
  21.         motorPins[i][3] = 1;
  22.     }
  23.     delay(2300); //go for 1 second
  24.     //digitalWrite(STBY, LOW);
  25.     Standby(); //stop
  26.     Serial.begin(9600);   // We'll send debugging information via the Serial monitor
  27.     int incomingByte = 0;
  28. }
  29.  
  30. void move(int motor, int speed, int direction) {
  31.   move(motor, speed, direction, false);
  32. }
  33.  
  34. void move(int motor, int speed, int direction, boolean override) {
  35.     if (!override && direction == motorPins[motor][2]) {
  36.         digitalWrite(motorPins[motor][0], LOW);
  37.         digitalWrite(motorPins[motor][1], LOW);
  38.         return;
  39.     }
  40.    
  41.     boolean inPin1 = LOW;
  42.     boolean inPin2 = HIGH;
  43.    
  44.     if (direction == 1) {
  45.         inPin1 = HIGH;
  46.         inPin2 = LOW;
  47.     }
  48.    
  49.     digitalWrite(STBY, HIGH); //disable standby
  50.     Serial.print("Motor ");
  51.     Serial.print(motor);
  52.     Serial.print(" Is moving, POS is set to ");
  53.     Serial.println(motorPins[motor][2]);
  54.     digitalWrite(motorPins[motor][0], inPin1);
  55.     digitalWrite(motorPins[motor][1], inPin2);
  56.     analogWrite(PWMA, speed);
  57. }
  58.  
  59. void Standby() {
  60.     //enable standby
  61.     digitalWrite(STBY, LOW);
  62. }
  63.  
  64. void SyPrint(){
  65.     for (int i = 1; i  < 5; i++){
  66.         Serial.print("Motor POS " );
  67.         Serial.print(i);
  68.         Serial.print(" = " );
  69.         Serial.print(motorPins[i][2]);
  70.         Serial.print(" ");
  71.     }
  72.    
  73.     Serial.println(" ");
  74. }
  75.  
  76.  
  77. void loop(void) {
  78.     Standby(); //stopE
  79.     if (Serial.available() > 0) {
  80.        
  81.         int inByte = Serial.read();
  82.         switch (inByte) {
  83.                
  84.             case 'A'://Close
  85.                 for (int i = 1; i< 5; i++){
  86.                     move(i, 255, 0);
  87.                 }
  88.                 delay(2100); //go for 1 second
  89.                 //Standby(); //stopE
  90.                 SyPrint();
  91.                 break;
  92.                
  93.             case 'B': //Open
  94.                 for (int i = 2; i< 6; i++){
  95.                     move(i, 255, 1);
  96.                 }
  97.                 delay(2300); //go for 1 second
  98.                 //Standby(); //stop
  99.                 SyPrint();
  100.                 break;
  101.                
  102.             case 'C':// Slow Close
  103.                 for (int i = 2; i< 6; i++){
  104.                     move(i, 155, 0);
  105.                 }
  106.                 delay(3000); //go for 1 secondB
  107.                 //Standby(); //stop
  108.                 break;
  109.                
  110.             case 'D'://Point
  111.                 for (int i = 2; i< 5; i++){
  112.                     move(i, 255, 0);
  113.                 }
  114.                 move(5, 255, 1);
  115.                 delay(2300); //go for 1 second
  116.                 //Standby(); //stop
  117.                 break;
  118.                
  119.             case 'E': //LongHorns
  120.                 move(5, 255, 0); //motor 5, full speed, close //speed set
  121.                 move(4, 255, 1); //motor 2, full speed, close
  122.                 move(3, 255, 0); //motor 3, full speed, close
  123.                 move(2, 255, 1); //motor 4, full speed, close
  124.                 delay(2300); //go for 1 second    
  125.                 //Standby(); //stop
  126.                
  127.                 break;
  128.                
  129.                 // default: // turn all the motors off:
  130.                 //  Standby(); //stop
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement