Robotic pianospelare (3 / 3 steg)
Steg 3: Ansluta servon till Arduino
Anslut två servon direkt till Arduino Uno 5vcc, jord och signal stift 9 och 11.
Kör Arduino skiss enligt följande:
#include servo.h
Servo servo1, servo3;
int ledPin = 13. Välj den PIN-kod för LED
void setup() {
Serial.BEGIN(9600);
pinMode (ledPin, produktionen); förklara ledPin som en utgång
servo1.attach(9);
Delay(10);
servo1.write(110); sätta fingret på startposition
servo3.attach(11);
Delay(10);
servo3.write(71); Placera reglaget på startposition
Delay(5000); vänta 5 sekunder innan du börjar
}
void playKey (int slidePos) {
servo3.write(slidePos); Flytta skjutreglaget servo till nyckelposition
Delay(300); att reglaget tid att komma dit
servo1.write(85); flytta fingret nedåt och tryck på tangenten
Delay(100); ge tid att flytta fingret nedåt
servo1.write(110); plocka finger tillbaka upp
Delay(300); ge tid att plocka finger upp innan nästa skjutreglaget flytta
}
void loop() {
digitalWrite(ledPin,HIGH);
/ * playKey (165); //f delay(500); playKey (149), //g playKey (138) //a playKey (127) //b playKey (116); //c playKey (105); //d playKey (94); //e playKey (83); //f playKey (72), //g playKey (61); //a playKey (50), //b playKey (28), //c playKey (15); //d * /
cetk / /
playKey(71); playKey(60); playKey(83); playKey(170); Delay(400); playKey(116); Delay(2000);
Avengers / /
playKey(72); playKey(94); playKey(83); playKey(50); playKey(15); playKey(28); playKey(72); playKey(94); playKey(83); Delay(2000); Amazing grace playKey(160); playKey(116); playKey(94); playKey(94); playKey(105); playKey(116); playKey(138); playKey(149); Delay(2000);
Indiana jones
playKey(138); playKey(127); playKey(116); playKey(83); Delay(500); playKey(149); playKey(138); playKey(127); Delay(500); playKey (116), //c playKey (105), //d playKey (94); //e playKey (50), //c playKey (105), //d playKey (94); //e playKey (83); //f playKey (72), //g playKey (61), //a delay(2000);
Gilligan
playKey (138); //f playKey (105) //g playKey (61), //a playKey (61); //f playKey (61), //g playKey (72); //a playKey (94); //f playKey (116); //g delay(500); playKey (138); //f playKey (105) //g playKey (61), //a playKey (61); //f playKey (61), //g playKey (72); //a delay(500); playKey (138); //f playKey (105) //g playKey (61), //a playKey (61); //f playKey (61), //g playKey (72); //a playKey (28); //a delay(500); playKey (72), //a playKey (83), //a delay(500); playKey (94) //a playKey (116) //a playKey (105); //a delay(2000);
någonstans över regnbågen
playKey(127); Delay(300); playKey(50); Delay(300); playKey (61); //f delay(300); playKey(83); playKey (72), //g playKey (61), //a playKey (50), //b delay(200); playKey(125);delay(300); playKey(72);delay(300); playKey(83); CLI(); / * playKey (149), //g playKey (138) //a playKey (127) //b playKey (116); //c playKey (105); //d playKey (94); //e playKey (83); //f playKey (72), //g playKey (61); //a playKey (50), //b playKey (28), //c playKey (15); //d * /
}