Advertisement
Ceiifadore

Novo controle

Jul 2nd, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. #include <Servo.h> //BIBLIOTECA DE FUNÇÕES COM MOTORES SERVOS
  2.  
  3. // DECLARAÇÃO DOS MOTORES UZADOS NO PROJETO...
  4. Servo servoEsq; // base 360°
  5. Servo servoGarra; //GARRA DO B RAÇO MECÂNICO...
  6. Servo servoBraco; //MOTOR RESPONSÁVEL PELA MOVIMENTAÇÃO VERTICL DO BRAÇO...
  7. Servo servoBraco2; // pulso
  8.  
  9. int posicaoPulso = 80;
  10. int posicaoBraco = 0;
  11. int posicaoGarra = 80;
  12.  
  13.  
  14.  
  15. void setup() //FUNÇÃO ONDE SÃO ESPECIFICADAS AS CONFIGURAÇÕES DO PROJETO...
  16. {
  17. //ATRIBUIÇÃO DE PINOS PARA OS MOTORES
  18. servoGarra.attach(3);
  19. servoBraco.attach(5);
  20. servoBraco2.attach(6);
  21. servoEsq.attach(9);
  22.  
  23. Serial.begin(9600);
  24.  
  25. }
  26.  
  27. void parado() //FUNÇÃO QUE MANTÉN OS DOIS SERVOS DE ROTAÇÃO CONTÍNUA USADOS NAS RODAS PARADOS (ROBÔ PARADO)...
  28. {
  29. servoEsq.write(90);
  30. }
  31. void direita() //FUNÇÃO RESPONSÁVEL POR GIRAR A BASE PARA A DIREITA...
  32. {
  33. servoEsq.write(0);
  34. delay(1300); //GIRA POR ATÉ ATINGIR UM ÂNGULO DE APROX.90 GRAUS E PARA...
  35.  
  36. }
  37.  
  38. void esquerda() //FUNÇÃO RESPONSÁVEL POR GIRAR A BASE PARA A ESQUERDA...
  39. {
  40. servoEsq.write(180);
  41. delay(1300); //GIRA POR ATÉ ATINGIR UM ÂNGULO DE APROX. 90 GRAUS E PARA...
  42.  
  43. }
  44.  
  45. void sobeBraco() // FUNÇÃO RESPONSÁVELPORLEVANTAR O BRAÇO MECÂNICO...
  46. {
  47. int i;
  48. for( i = posicaoBraco;i<90;i++)
  49. {
  50. servoBraco.write(180-i);
  51. delay(45);
  52. }
  53. posicaoBraco = i;
  54. }
  55. void PulsoBaixo() // Levantar pulso
  56. {
  57. int i;
  58. for( i = posicaoPulso;i<90;i++)
  59. {
  60. servoBraco2.write(180-i);
  61. delay(45);
  62. }
  63. posicaoPulso = i;
  64. }
  65. void PulsoCima() // Abaixar pulso
  66. {
  67. int i;
  68. for( i = posicaoPulso; i > 0;i--)
  69. {
  70. servoBraco2.write(180-i);
  71. delay(45);
  72. }
  73. posicaoPulso = i;
  74. }
  75.  
  76. void baixaBraco() //FUNÇÃO RESPONSÁVEL POR BAIXAR O BRAÇO MECÂNICO...
  77. {
  78. int i;
  79. for(i = posicaoBraco; i > 0;i--)
  80. {
  81. servoBraco.write(180-i);
  82. delay(45);
  83. }
  84. posicaoBraco = i;
  85. }
  86.  
  87. void abre() // FUNÇÃO QU ABRE A GARRA...
  88. {
  89. int i;
  90. for(i = posicaoGarra; i < 160;i++)
  91. {
  92. servoGarra.write(i);
  93. delay(40);
  94. }
  95. posicaoGarra = i;
  96. }
  97.  
  98. void fecha() // FUNÇÃO QU FECHA A GARRA...
  99. {
  100. int i;
  101. for(i = posicaoGarra; i > 80;i--)
  102. {
  103. servoGarra.write(i);
  104. delay(40);
  105. }
  106. posicaoGarra = i;
  107. }
  108.  
  109.  
  110. void loop()
  111. {
  112.  
  113. char tecla = Serial.read(); // A PORTA SERIAL LÊ UMA TECLA DIGITADA NO TECLADO DO COMPUTADOR...
  114. //E DE ACORDO COM O CARACTER LIDO CHAMA UMA DAS FUNÇÕES ACIMA...
  115.  
  116. if(tecla == 'd' || tecla == 'D' ) //CASO PRESSIONE A TECLA 'D', O ROBO GIRA PARA A DIREITA...
  117. {
  118. direita();
  119. }
  120. else if(tecla == 'a' || tecla == 'A') //CASO PRESSIONE A TECLA 'E', O ROBO GIRA PARA A ESQUERDA...
  121. {
  122. esquerda();
  123. }
  124.  
  125. else if (tecla == 'q' || tecla == 'Q') //CASO PRESSIONE A TECLA 'A', O ROBO ABRE A GARRA...
  126. {
  127. abre();
  128. }
  129. else if(tecla == 'e' || tecla == 'E') //CASO PRESSIONE A TECLA 'F', O ROBO FECHA A GARRA...
  130. {
  131. fecha();
  132. }
  133. else if (tecla == 'w' || tecla == 'W') //CASO PRESSIONE A TECLA 'S', O ROBO SOBE O BRAÇO...
  134. {
  135. sobeBraco();
  136. }
  137. else if (tecla == 's' || tecla == 'S') //CASO PRESSIONE A TECLA 'B', O ROBO BAIXA O BRAÇO...
  138. {
  139. baixaBraco();
  140. }
  141. else if (tecla == 'j' || tecla == 'J') //CASO PRESSIONE A TECLA 'B', O ROBO SOBE O PULSO...
  142. {
  143. PulsoCima();
  144. }
  145. else if (tecla == 'k' || tecla == 'K') //CASO PRESSIONE A TECLA 'B', O ROBO BAIXA O PULSO...
  146. {
  147.  
  148. PulsoBaixo();
  149. }
  150.  
  151. else // CASO NÃO PRESSIONE NENHUMA TECLA O ROBÔ PERMANECE PARADO...
  152. {
  153. parado();
  154. }
  155.  
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement