SHARE
TWEET

Untitled

a guest Aug 4th, 2016 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LinkedList.h>
  2. #include <Servo.h>
  3. int i, j, k, r, c, x, t;
  4.  
  5. // potentiometer pins
  6. #define BASE_POT_PIN A0
  7. #define SHOULDER_POT_PIN A2
  8. #define SHOULDER2_POT_PIN A3
  9. #define ELBOW_POT_PIN A1
  10.  
  11. // servo pins
  12. #define BASE_SERVO_PIN 6
  13. #define SHOULDER_SERVO_PIN 8
  14. #define SHOULDER2_SERVO_PIN 7
  15. #define ELBOW_SERVO_PIN 9
  16.  
  17. // motion constants
  18. #define MOTION_DELAY 15
  19.  
  20. // servo objects
  21. Servo base_servo, shoulder_servo, shoulder2_servo, elbow_servo;
  22.  
  23. // history of servo positions
  24. LinkedList<int> *base_history = new LinkedList<int>();
  25. LinkedList<int> *shoulder_history = new LinkedList<int>();
  26. LinkedList<int> *shoulder2_history = new LinkedList<int>();
  27. LinkedList<int> *elbow_history = new LinkedList<int>();
  28.  
  29.  
  30.  
  31. int a[4][9][8]=
  32.  {
  33.    {
  34.     {48,44,40,38,34,30,27,22},
  35.     {39,39,38,37,36,35,34,33},
  36.     {49,45,42,39,35,31,26,22},
  37.     {48,46,43,39,37,31,27,22},
  38.     {48,46,42,39,37,31,28,22},
  39.     {48,45,42,38,35,31,27,22},
  40.     {48,44,42,38,35,30,26,22},
  41.     {48,45,42,38,34,30,26,22},
  42.     {48,45,42,37,33,29,26,22}
  43.    },
  44.    {
  45.     {40,40,42,42,42,42,42,40},
  46.     {46,46,47,46,46,46,46,45},
  47.     {49,49,50,54,53,53,53,52},
  48.     {56,56,54,57,54,57,57,55},
  49.     {58,58,60,58,59,59,59,58},
  50.     {62,62,64,64,64,64,56,60},
  51.     {63,63,65,67,67,67,65,62},
  52.     {63,65,67,68,68,66,66,62},
  53.     {62,62,66,68,68,67,63,59}
  54.    },
  55.    {
  56.     {140,140,138,138,138,138,138,140},
  57.     {134,134,133,134,134,134,134,134},
  58.     {131,131,130,126,127,127,127,128},
  59.     {124,124,126,123,121,123,123,125},
  60.     {122,122,120,122,120,121,121,122},
  61.     {118,118,116,116,116,116,124,120},
  62.     {117,118,115,113,113,113,115,118},
  63.     {117,115,113,112,112,114,114,118},
  64.     {118,118,113,112,112,113,117,121}
  65.   },
  66.   {
  67.     {169,170,169,173,171,171,171,162},
  68.     {171,171,171,171,171,171,171,171},
  69.     {170,170,171,178,175,178,176,173},
  70.     {174,176,175,178,171,178,177,173},
  71.     {173,173,175,175,173,175,175,172},
  72.     {171,170,175,169,176,176,166,168},
  73.     {166,178,169,170,172,170,175,162},
  74.     {160,167,170,172,172,169,164,161},
  75.     {156,156,163,165,165,162,158,149}
  76.   }
  77. };
  78. void loopthrough (int values[4][9][8]){
  79.   int smiles [9][8]={
  80.     {0,0,0,0,0,0,0,0},
  81.     {1,1,1,1,1,1,1,1},
  82.     {0,0,0,0,0,0,0,0},
  83.     {0,0,0,0,1,0,0,0},
  84.     {0,0,0,0,0,0,0,0},
  85.     {0,1,0,0,0,0,0,0},
  86.     {0,0,0,0,0,0,1,0},
  87.     {0,0,0,0,0,0,0,0}
  88.   };
  89.  
  90.   for(i=0; i<9; i++){
  91.     for(j=0; j<8; j++){
  92.       if (smiles[i][j]==1){
  93.         r=i;
  94.         c=j;
  95.           base_servo.write(a[0][r][c]);
  96.           shoulder_servo.write(a[1][r][c]);
  97.           shoulder2_servo.write(a[2][r][c]);
  98.           delay(500);
  99.           elbow_servo.write(a[3][r][c]);
  100.           delay(1500);
  101.           base_servo.write(18);
  102.           elbow_servo.write(180);
  103.           shoulder_servo.write(60);
  104.           shoulder2_servo.write(120);
  105.           delay(500);
  106.         }
  107.       }
  108.     }
  109.   }
  110.  
  111.  
  112. /*
  113.  * Detaches all servos.
  114.  */
  115. void detachAll() {
  116.   base_servo.detach();
  117.   shoulder_servo.detach();
  118.   shoulder2_servo.detach();
  119.   elbow_servo.detach();
  120.   delay(100);
  121. }
  122.  
  123. /*
  124.  * Attaches all servos.
  125.  */
  126. void attachAll() {
  127.   base_servo.attach(BASE_SERVO_PIN);
  128.   shoulder_servo.attach(SHOULDER_SERVO_PIN);
  129.   shoulder2_servo.attach(SHOULDER2_SERVO_PIN);
  130.   elbow_servo.attach(ELBOW_SERVO_PIN);
  131.   delay(100);
  132. }
  133.  
  134. void setup() {
  135.   Serial.begin(9600);
  136.   attachAll();
  137.   Serial.println("---   START   ---");
  138. }
  139.  
  140. void loop() {
  141.   loopthrough(a);
  142.   loopthrough(a);
  143.   loopthrough(a);
  144.   loopthrough(a);  
  145. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top