Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Make a Servo Move to Sound.
- This example code is in the public domain.
- 2012 by Cenk Özdemir
- */
- #include <Servo.h>
- Servo myservo1;
- Servo myservo2;
- Servo myservo3;
- int ServoPin1 = 8;
- int ServoPin2 = 9;
- int ServoPin3 = 10;
- int SoundInPinLeg= A0;
- int SoundInPinHand = A1;
- int LedPin = 6;
- void setup() {
- // initialize
- myservo1.attach(ServoPin1);
- myservo2.attach(ServoPin2);
- myservo3.attach(ServoPin3);
- pinMode(SoundInPinLeg, INPUT);
- pinMode(SoundInPinHand, INPUT);
- pinMode(LedPin, OUTPUT);
- }
- void loop() {
- int sensorValue1 = analogRead(SoundInPinLeg);
- int sensorValue2 = analogRead(SoundInPinHand);
- int LEDValue = map(sensorValue1,0,512,0,255);
- sensorValue1 = map(sensorValue1,0,512,0,180);
- sensorValue2 = map(sensorValue2,0,512,0,180);
- myservo1.write(90);
- myservo2.write(90);
- myservo3.write(90);
- int MoveDelayValue1 = map(sensorValue1,0,255,0,sensorValue1);
- int MoveDelayValue2 = map(sensorValue2,0,255,0,sensorValue2);
- if (sensorValue1 > 2) // to cut off some static readings only if the reading gets higher then 33 it begings to work
- delay(1); // a static delay to smooth things out...
- if (sensorValue2 > 2) { // to cut off some static readings only if the reading gets higher then 33 it begings to work
- delay(1);
- myservo1.write(sensorValue1);
- myservo2.write(sensorValue1);
- myservo3.write(sensorValue2);
- analogWrite(LedPin, sensorValue1);
- delay(MoveDelayValue1);
- }
- analogWrite(LedPin, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment