Advertisement
RuiViana

Parte_Inverte_Para_Motor

Nov 23rd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #define bot1 10
  2. #define bot2 11
  3. #define bot3 12
  4. #define led1 5
  5. #define led2 6
  6. #define led3 7
  7. #define led4 8
  8. int motor;
  9. //--------------------------------------
  10. void setup() {
  11. pinMode (bot1, INPUT_PULLUP);
  12. pinMode (bot2, INPUT_PULLUP);
  13. pinMode (bot3, INPUT_PULLUP);
  14. pinMode (led1, OUTPUT);
  15. pinMode (led2, OUTPUT);
  16. pinMode (led3, OUTPUT);
  17. pinMode (led4, OUTPUT);
  18. digitalWrite (led1, 0);
  19. digitalWrite (led2, 0);
  20. digitalWrite (led3, 0);
  21. digitalWrite (led4, 0);
  22. Serial.begin (9600);
  23. motor = 1;
  24. }
  25. //-------------------------------------
  26. void loop()
  27. {
  28.  
  29. if (motor == 1)
  30. {
  31. while(digitalRead (bot1)==LOW)
  32. {
  33. delay(10);
  34. GiraWise();
  35. }
  36. }
  37. if (motor == 1)
  38. {
  39. while(digitalRead (bot2)==LOW)
  40. {
  41. delay(10);
  42. GiraCounterWise();
  43. }
  44. }
  45. while(digitalRead (bot3)==LOW)
  46. {
  47. delay(10);
  48. Stop();
  49. }
  50. Serial.println(motor);
  51. }
  52. //-------------------------------------
  53. void GiraWise()
  54. {
  55. digitalWrite (led1, 1);
  56. digitalWrite (led2, 1);
  57. digitalWrite (led3, 0);
  58. digitalWrite (led4, 0);
  59. motor = 0;
  60. }
  61. //-------------------------------------
  62. void GiraCounterWise()
  63. {
  64. digitalWrite (led1, 0);
  65. digitalWrite (led2, 0);
  66. digitalWrite (led3, 1);
  67. digitalWrite (led4, 1);
  68. motor = 0;
  69. }
  70. //-------------------------------------
  71. void Stop()
  72. {
  73. digitalWrite (led1, 0);
  74. digitalWrite (led2, 0);
  75. digitalWrite (led3, 0);
  76. digitalWrite (led4, 0);
  77. motor = 1;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement