You are on page 1of 7

Edit with the Docs app

Make tweaks, leave comments, and share with others to edit at the same time.

NO THANKSUSE THE APP

6 Servo And 6 Potentiomers Code

#include <Servo.h>

Servo servo1;  

int potpin1 = 0;  

int val1;    

Servo servo2;  

int potpin2 = 1;  

int val2;    

Servo servo3;  

int potpin3 = 2;  

int val3;    

Servo servo4;
int potpin4 = 3;  

int val4;    

Servo servo5;

int potpin5 = 4;  

int val5;    

Servo servo6;

int potpin6 = 5;  

int val6;    

void setup()

  servo1.attach(3);  

  servo2.attach(5);  

  servo3.attach(6);  

  servo4.attach(9);  
  servo5.attach(10);  

  servo6.attach(11);  

void loop()

  val1 = analogRead(potpin1);            

  val1 = map(val1, 0, 1023, 0, 185 );

  servo1.write(val1);                

  val2 = analogRead(potpin2);            

  val2 = map(val2, 0, 1023, 0, 185 );

  servo2.write(val2);                

  val3 = analogRead(potpin3);            

  val3 = map(val3, 0, 1023, 0, 185 );

  servo3.write(val3);              

  val4 = analogRead(potpin4);            


  val4 = map(val4, 0, 1023, 0, 185 );

  servo4.write(val4);                

  val5 = analogRead(potpin5);        

  val5 = map(val5, 0, 1023, 0, 185 );

  servo5.write(val5);                

  val6 = analogRead(potpin6);            

  val6 = map(val6, 0, 1023, 0, 185 );

  servo6.write(val6);                

MiHu-Works

ARDUINO / ELEKTRONIK2

Töne in Bewegung umsetzen – Sound to move

VON MIHU · VERÖFFENTLICHT AUGUST 25, 2016 · AKTUALISIERT JANUAR 15, 2019
Mithilfe eines Microcontrollers, einem Mikrofon, einem Spektrumanalayzer IC und 2 Servomotoren
können Geräusche Frequenzabhängig in Bewegung gewandelt werden.

Update 15.01.2019: Hier ist mein Verwendeter Programmcode:

include <Servo.h>

Servo myservo1; // create servo object to control a servo

Servo myservo2;

int analogPin = A0; // read from multiplexer using analog input 0

int strobePin = A5; // strobe is attached to digital pin 2

int resetPin = A4; // reset is attached to digital pin 3

int spectrumValue[7]; // to hold a2d values

int filter=155;

void setup()

myservo1.attach(9); // attaches the servo on pin 9 to the servo object

myservo2.attach(5);

pinMode(analogPin, INPUT);

pinMode(strobePin, OUTPUT);

pinMode(resetPin, OUTPUT);
digitalWrite(resetPin, LOW);

digitalWrite(strobePin, HIGH);

Serial.begin(9600);

void loop()

// val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)

// val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)

// myservo.write(val); // sets the servo position according to the scaled value

// delay(15); // waits for the servo to get there

digitalWrite(resetPin, HIGH);

digitalWrite(resetPin, LOW);

for (int i=0;i<7;i++) {

digitalWrite(strobePin, LOW);

delayMicroseconds(30);

spectrumValue[i] = analogRead(analogPin);

spectrumValue[i] = constrain(spectrumValue[i],filter, 1023);

spectrumValue[i] = map(spectrumValue[i], filter,800,10,179);

Serial.print(spectrumValue[i]);

Serial.print(" ");

digitalWrite(strobePin, HIGH);

Serial.println();

myservo1.write(spectrumValue[2]); // sets the servo position according to the scaled value


delay(15); // waits for the servo to get there

myservo2.write(spectrumValue[4]); // sets the servo position according to the scaled value

delay(15); // waits for the servo to get there

// analogWrite(redPin, );

// analogWrite(redPin, spectrumValue[1]);

// analogWrite(greenPin, spectrumValue[3]);

// analogWrite(greenPin, spectrumValue[4]);

// analogWrite(bluePin, spectrumValue[5]);

// analogWrite(bluePin, spectrumValue[6]);

You might also like