/* Fab Academy Karaoke machine * David McCallum, Xavier Klein, Dima Paley, 2018 * sintheta.org * Code adapted from http://aconcaguasci.blogspot.nl/2016/11/arduino-cnc-shield-control-stepper.html * * For both X and Y, 50 steps per cm * * */ // Motor stuff const int ENABLE = 8 ; const int motorX_DIR = 5; //Direction pin const int motorX_STP = 2; //Step pin const int motorY_DIR = 7; //Direction pin const int motorY_STP = 4; //Step pin const int endstopPinX = 9; //Driver Timing int delayTime=450; //Delay between each pause (uS) int musicPulse = 150; // music timing pulse for the frere jacques functions. This is the beat! int line_roll = 1; // How many "line_step" steps to take up or down int step_size = 150; // The size of each step to the left or right int line_step = 350; // The size of each step up or down int initial_step = 3; // The size of the initial step to take from the start position // The basic move function void step(boolean dir, byte dirPin, byte stepperPin, int steps){ digitalWrite(dirPin, dir); for (int i = 0; i < steps; i++) { digitalWrite(stepperPin, HIGH); delayMicroseconds(delayTime); digitalWrite(stepperPin, LOW); delayMicroseconds(delayTime); } } // Move the motor until the endstop is reached void goHome() { while (digitalRead(endstopPinX) == HIGH) { // if the button isn't pressed, move the motor 1 step step(false, motorX_DIR, motorX_STP, 1); delayMicroseconds(delayTime); } step(true, motorX_DIR, motorX_STP, 50); } // This is a function to wait for a beat (or two beats, ore more) void empty_beat(int val){ delay(musicPulse * val); } // This is a function to move the finger motor left or right void full_beat(bool dir, float val){ step(dir, motorX_DIR, motorX_STP, int(val*step_size)); } // This is a function to move the paper roll motor up or down void line(bool dir, float val){ step(dir, motorY_DIR, motorY_STP, int(val*line_step)); } // This is the full song function // play Frere Jacques with alternating lines moving backwards (because the motor couldn't rewind fast enough) void frBackwards() { //initial step to the start of the page //fre full_beat(true,initial_step); empty_beat(2); for (int x = 0; x < 1 ; x++) { //re full_beat(true,1); // Moves the hand motor one step (3cm) to the right empty_beat(2); // Pauses the hand motor for 2 halves of a beat of the song //ja full_beat(true,2); empty_beat(2); //cque full_beat(true,2); empty_beat(2); line(false,line_roll); empty_beat(2); //fre full_beat(true,1); empty_beat(2); //re full_beat(false,1); empty_beat(2); //ja full_beat(false,2); empty_beat(2); //cque full_beat(false,2); empty_beat(2); line(false,line_roll); empty_beat(2); //dor full_beat(false,1); empty_beat(2); //mez full_beat(true,2); empty_beat(2); //vous full_beat(true,3); empty_beat(4); line(false,line_roll); empty_beat(2); //dor full_beat(true,1); empty_beat(2); //mez full_beat(false,2); empty_beat(2); //vous full_beat(false,3); empty_beat(4); line(false,line_roll); empty_beat(2); full_beat(false,1); empty_beat(1); //son full_beat(true,1); //nez empty_beat(1); //les full_beat(true,1.5); empty_beat(1); //ma full_beat(true,1.5); empty_beat(1); //ti full_beat(true,1); empty_beat(2); //nez full_beat(true,1); empty_beat(2); line(false,line_roll); empty_beat(2); full_beat(true,0.1); //son full_beat(false,1.1); //nez empty_beat(1); //les full_beat(false,1.5); empty_beat(1); //ma full_beat(false,1.5); empty_beat(1); //ti full_beat(false,1); empty_beat(2); //nez full_beat(false,1); empty_beat(2); line(false,line_roll); empty_beat(2); full_beat(false,0.1); full_beat(true,0.6); //ding empty_beat(2); //ding full_beat(true,2.5); empty_beat(2); //dong full_beat(true,2.5); empty_beat(2); line(false,line_roll); empty_beat(2); full_beat(true,0.1); //ding empty_beat(2); //ding full_beat(false,2.6); empty_beat(2); //dong full_beat(false,2.5); empty_beat(2); } } void setup(){ // serial.begin(9600); pinMode(motorX_DIR, OUTPUT); pinMode(motorX_STP, OUTPUT); pinMode(motorY_DIR, OUTPUT); pinMode(motorY_STP, OUTPUT); pinMode(ENABLE, OUTPUT); digitalWrite(ENABLE, LOW); pinMode(endstopPinX, INPUT_PULLUP); goHome(); // zero the motor to the edge delay(5000); frBackwards(); goHome(); line(true,7*line_roll); } void loop(){ }