Guest User

Untitled

a guest
Jul 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include <Servo.h> // Include servo library
  2. Servo servoRight;
  3. Servo servoLeft;
  4.  
  5. int PIEZOPIN = A0;
  6.  
  7. int button = 2;
  8.  
  9. int lwskr = 5;
  10. int rwskr = 7;
  11.  
  12. int ired = A1;
  13.  
  14. //int note_A4 = 440;
  15. //int note_As4 = 466; int note_Bb4 = note_As4;
  16. //int note_B4 = 494;
  17. //int note_C5 = 523;
  18. //int note_Cs5 = 554; int note_Db5 = note_Cs5;
  19. //int note_D5 = 587;
  20. //int note_Ds5 = 622; int note_Eb5 = note_Ds5;
  21. //int note_E5 = 659;
  22. //int note_F5 = 698;
  23. //int note_Fs5 = 740; int note_Gb5 = note_Fs5;
  24. //int note_G5 = 784;
  25. //int note_Gs5 = 830; int note_Ab5 = note_Gs5;
  26.  
  27. void setup() {
  28. Serial.begin(9600); // open serial port
  29. pinMode(lwskr,INPUT); // declare whiskers as inputs
  30. pinMode(rwskr,INPUT); // read values
  31. pinMode(button, INPUT);
  32. servoLeft.attach(13); // Attach left signal to pin 13
  33. servoRight.attach(12); // Attach right signal to pin 12
  34. servoLeft.writeMicroseconds(1500); // Calibrate left servo
  35. servoRight.writeMicroseconds(1500);// Calibrate right servo
  36. }
  37. void moveKitty(){
  38. forward(500);
  39. delay(500);
  40. }
  41.  
  42. void stopKitty(){
  43. servoRight.writeMicroseconds(1500);
  44. servoLeft.writeMicroseconds(1500);
  45. delay(1);
  46. }
  47.  
  48. // clock is 1500 - 2000
  49. // counter is 1000 - 1500
  50.  
  51. void clockw(int tim){
  52. servoLeft.writeMicroseconds(2000);
  53. servoRight.writeMicroseconds(2000);
  54. delay(tim);
  55. }
  56.  
  57. void counter(int tim){
  58. servoRight.writeMicroseconds(1000);
  59. servoLeft.writeMicroseconds(1000);
  60. delay(tim);
  61. }
  62.  
  63. void leftturn(int tim){
  64. servoRight.writeMicroseconds(1000);
  65. delay(tim);
  66. }
  67.  
  68. void rightturn(int tim){
  69. servoLeft.writeMicroseconds(1000);
  70. delay(tim);
  71. }
  72.  
  73. void backward(int tim){
  74. servoRight.writeMicroseconds(1700);
  75. servoLeft.writeMicroseconds(1300);
  76. delay(tim);
  77. }
  78.  
  79. void forward(int tim){
  80. servoRight.writeMicroseconds(1300);
  81. servoLeft.writeMicroseconds(1700);
  82. delay(tim);
  83. }
  84.  
  85. void loop() {
  86. // tone(PIEZOPIN,200,500);
  87. // delay(500);
  88.  
  89. int lwskrval = digitalRead(lwskr);
  90. int rwskrval = digitalRead(rwskr);
  91. int pushval = digitalRead(button);
  92. int iredval = analogRead(ired);
  93.  
  94. if (lwskrval == 1 && rwskrval == 1){
  95. moveKitty();
  96. }
  97. else if(lwskrval == 0 || rwskrval == 0){
  98. stopKitty();
  99. backward(500);
  100. clockw(500);
  101. }
  102. else if (lwskrval == 0){
  103. stopKitty();
  104. rightturn(500);
  105. }
  106. else if (rwskrval == 0){
  107. stopKitty();
  108. leftturn(500);
  109. }
  110. delay(500);
  111.  
  112. // if (pushval == 0){
  113. // clockw(1000);
  114. // counter(1000);
  115. // delay(2000);
  116. // }
  117. }
Add Comment
Please, Sign In to add comment