Advertisement
AndrejKozlovsky

Untitled

Apr 25th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. int motor1_enable = A8;
  2. int motor1_in1 = A9;
  3. int motor1_in2 = A10;
  4. int motor2_enable = 7;
  5. int motor2_in1 = 6;
  6. int motor2_in2 = 5;
  7. int motor3_enable = 10;
  8. int motor3_in1 = 9;
  9. int motor3_in2 = 8;
  10. int motor4_enable = 2;
  11. int motor4_in1 = 3;
  12. int motor4_in2 = 4;
  13. int motor5_enable = 46;
  14. int motor5_in1 = 45;
  15. int motor5_in2 = 4;
  16. int light_enable = A6;
  17. int light_in1 = A7;
  18. int light_in2 = A5;
  19.  
  20. void setup() {
  21. Serial.begin(9600);
  22.  
  23. pinMode(motor1_enable, OUTPUT);
  24. pinMode(motor1_in1, OUTPUT);
  25. pinMode(motor1_in2, OUTPUT);
  26. pinMode(motor2_enable, OUTPUT);
  27. pinMode(motor2_in1, OUTPUT);
  28. pinMode(motor2_in2, OUTPUT);
  29. pinMode(motor3_enable, OUTPUT);
  30. pinMode(motor3_in1, OUTPUT);
  31. pinMode(motor3_in2, OUTPUT);
  32. pinMode(motor4_enable, OUTPUT);
  33. pinMode(motor4_in1, OUTPUT);
  34. pinMode(motor4_in2, OUTPUT);
  35. pinMode(motor5_enable, OUTPUT);
  36. pinMode(motor5_in1, OUTPUT);
  37. pinMode(motor5_in2, OUTPUT);
  38. pinMode(light_enable, OUTPUT);
  39. pinMode(light_in1, OUTPUT);
  40. pinMode(light_in2, OUTPUT);
  41. }
  42.  
  43. void wristOpen() {
  44. digitalWrite(motor1_enable, HIGH);
  45. digitalWrite(motor1_in1, HIGH);
  46. digitalWrite(motor1_in2, LOW);
  47. }
  48.  
  49. void wristClose() {
  50. digitalWrite(motor1_enable, HIGH);
  51. digitalWrite(motor1_in2, HIGH);
  52. digitalWrite(motor1_in1, LOW);
  53. }
  54.  
  55. void wristStop() {
  56. digitalWrite(motor1_enable, LOW);
  57. digitalWrite(motor1_in1, LOW);
  58. digitalWrite(motor1_in2, LOW);
  59. }
  60.  
  61. void handUp() {
  62. digitalWrite(motor2_enable, HIGH);
  63. digitalWrite(motor2_in1, HIGH);
  64. digitalWrite(motor2_in2, LOW);
  65. }
  66.  
  67. void handDown() {
  68. digitalWrite(motor2_enable, HIGH);
  69. digitalWrite(motor2_in2, HIGH);
  70. digitalWrite(motor2_in1, LOW);
  71. }
  72.  
  73. void handStop() {
  74. digitalWrite(motor2_enable, LOW);
  75. digitalWrite(motor2_in2, LOW);
  76. digitalWrite(motor2_in1, LOW);
  77. }
  78.  
  79. void elbowUp() {
  80. digitalWrite(motor3_enable, HIGH);
  81. digitalWrite(motor3_in1, HIGH);
  82. digitalWrite(motor3_in2, LOW);
  83. }
  84.  
  85. void elbowDown() {
  86. digitalWrite(motor3_enable, HIGH);
  87. digitalWrite(motor3_in2, HIGH);
  88. digitalWrite(motor3_in1, LOW);
  89. }
  90.  
  91. void elbowStop() {
  92. digitalWrite(motor3_enable, LOW);
  93. digitalWrite(motor3_in2, LOW);
  94. digitalWrite(motor3_in1, LOW);
  95. }
  96.  
  97. void shoulderUp() {
  98. digitalWrite(motor4_enable, HIGH);
  99. digitalWrite(motor4_in1, HIGH);
  100. digitalWrite(motor4_in2, LOW);
  101. }
  102.  
  103. void shoulderDown() {
  104. digitalWrite(motor4_enable, HIGH);
  105. digitalWrite(motor4_in2, HIGH);
  106. digitalWrite(motor4_in1, LOW);
  107. }
  108.  
  109. void shoulderStop() {
  110. digitalWrite(motor4_enable, LOW);
  111. digitalWrite(motor4_in1, LOW);
  112. digitalWrite(motor4_in2, LOW);
  113. }
  114.  
  115. void baseLeft() {
  116. digitalWrite(motor5_enable, HIGH);
  117. digitalWrite(motor5_in1, HIGH);
  118. digitalWrite(motor5_in2, LOW);
  119. }
  120.  
  121. void baseRight() {
  122. digitalWrite(motor5_enable, HIGH);
  123. digitalWrite(motor5_in2, HIGH);
  124. digitalWrite(motor5_in1, LOW);
  125. }
  126.  
  127. void baseStop() {
  128. digitalWrite(motor5_enable, LOW);
  129. digitalWrite(motor5_in2, LOW);
  130. digitalWrite(motor5_in1, LOW);
  131. }
  132.  
  133. void lightOn() {
  134. digitalWrite(light_enable, HIGH);
  135. digitalWrite(light_in1, HIGH);
  136. digitalWrite(light_in2, LOW);
  137. }
  138.  
  139. void lightOff() {
  140. digitalWrite(light_enable, HIGH);
  141. digitalWrite(light_in2, HIGH);
  142. digitalWrite(light_in1, LOW);
  143. }
  144.  
  145. void lightStop() {
  146. digitalWrite(light_enable, LOW);
  147. digitalWrite(light_in1, LOW);
  148. digitalWrite(light_in2, LOW);
  149. }
  150.  
  151. void stopMove() {
  152. digitalWrite(motor1_enable, LOW);
  153. digitalWrite(motor1_in1, LOW);
  154. digitalWrite(motor1_in2, LOW);
  155.  
  156. digitalWrite(motor2_enable, LOW);
  157. digitalWrite(motor2_in1, LOW);
  158. digitalWrite(motor2_in2, LOW);
  159.  
  160. digitalWrite(motor3_enable, LOW);
  161. digitalWrite(motor3_in1, LOW);
  162. digitalWrite(motor3_in2, LOW);
  163.  
  164. digitalWrite(motor4_enable, LOW);
  165. digitalWrite(motor4_in1, LOW);
  166. digitalWrite(motor4_in2, LOW);
  167.  
  168. digitalWrite(motor5_enable, LOW);
  169. digitalWrite(motor5_in1, LOW);
  170. digitalWrite(motor5_in2, LOW);
  171.  
  172. digitalWrite(light_enable, LOW);
  173. digitalWrite(light_in1, LOW);
  174. digitalWrite(light_in2, LOW);
  175. }
  176.  
  177. void loop() {
  178. if (Serial.available() > 0) {
  179. int inByte = Serial.read();
  180.  
  181. if (inByte == 'a') {
  182. wristClose();
  183. }
  184. if (inByte == 'q') {
  185. wristOpen();
  186. }
  187. if (inByte == 'y') {
  188. wristStop();
  189. }
  190.  
  191. if (inByte == 'w') {
  192. handUp();
  193. }
  194. if (inByte == 's') {
  195. handDown();
  196. }
  197. if (inByte == 'x') {
  198. handStop();
  199. }
  200.  
  201. if (inByte == 'e') {
  202. elbowUp();
  203. }
  204. if (inByte == 'd') {
  205. elbowDown();
  206. }
  207. if (inByte == 'c') {
  208. elbowStop();
  209. }
  210.  
  211. if (inByte == 'f') {
  212. shoulderDown();
  213. }
  214. if (inByte == 'r') {
  215. shoulderUp();
  216. }
  217. if (inByte == 'v') {
  218. shoulderStop();
  219. }
  220.  
  221. if (inByte == '.') {
  222. baseLeft();
  223. }
  224. if (inByte == ',') {
  225. baseRight();
  226. }
  227. if (inByte == '-') {
  228. baseStop();
  229. }
  230.  
  231. if (inByte == 'g') {
  232. lightOff();
  233. }
  234. if (inByte == 't') {
  235. lightOn();
  236. }
  237. if (inByte == 'b') {
  238. lightStop();
  239. }
  240.  
  241. if (inByte == '0') {
  242. stopMove();
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement