homework5: musical note

i find that the shape of the rotate device is like the music note , so i have this idea .

#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
int voice;
int speaker = 10;

void setup()
{
Serial.begin(9600);
myservo.attach(9);
pinMode(speaker,OUTPUT);
}
void loop()
{

val = analogRead(potpin);

voice = map(val,0,1023,0,4000);
val = map(val, 0, 1023, 0, 180);

tone(speaker,voice);

myservo.write(val);

delay(15);
}

Leave a Reply

Your email address will not be published. Required fields are marked *