Guest User

Untitled

a guest
Jun 6th, 2016
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. /*
  2. Make a Servo Move to Sound.
  3. This example code is in the public domain.
  4. 2012 by Cenk Özdemir
  5. */
  6. #include <Servo.h>
  7.  
  8. Servo myservo1;
  9. Servo myservo2;
  10. Servo myservo3;
  11.  
  12. int ServoPin1 = 8;
  13. int ServoPin2 = 9;
  14. int ServoPin3 = 10;
  15. int SoundInPinLeg= A0;
  16. int SoundInPinHand = A1;
  17. int LedPin = 6;
  18.  
  19. void setup() {
  20. // initialize
  21. myservo1.attach(ServoPin1);
  22. myservo2.attach(ServoPin2);
  23. myservo3.attach(ServoPin3);
  24. pinMode(SoundInPinLeg, INPUT);
  25. pinMode(SoundInPinHand, INPUT);
  26. pinMode(LedPin, OUTPUT);
  27. }
  28.  
  29. void loop() {
  30.  
  31. int sensorValue1 = analogRead(SoundInPinLeg);
  32. int sensorValue2 = analogRead(SoundInPinHand);
  33.  
  34. int LEDValue = map(sensorValue1,0,512,0,255);
  35.  
  36.  
  37. sensorValue1 = map(sensorValue1,0,512,0,180);
  38. sensorValue2 = map(sensorValue2,0,512,0,180);
  39.  
  40. myservo1.write(90);
  41. myservo2.write(90);
  42. myservo3.write(90);
  43.  
  44. int MoveDelayValue1 = map(sensorValue1,0,255,0,sensorValue1);
  45. int MoveDelayValue2 = map(sensorValue2,0,255,0,sensorValue2);
  46.  
  47. if (sensorValue1 > 2) // to cut off some static readings only if the reading gets higher then 33 it begings to work
  48. delay(1); // a static delay to smooth things out...
  49. if (sensorValue2 > 2) { // to cut off some static readings only if the reading gets higher then 33 it begings to work
  50. delay(1);
  51.  
  52.  
  53. myservo1.write(sensorValue1);
  54. myservo2.write(sensorValue1);
  55. myservo3.write(sensorValue2);
  56. analogWrite(LedPin, sensorValue1);
  57.  
  58.  
  59. delay(MoveDelayValue1);
  60. }
  61. analogWrite(LedPin, 0);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment