I have this code to control my steppermotor in Javascript with an Espruino.
function motorStep(mySteps){
var stepperPins = [C6,C7,C8,C9]; // Change these to your pins (digital output)
var stepBits = [0b0110,0b0101,0b1001,0b1010];
if (mySteps<0) //reverse
{
stepBits.reverse();
mySteps = -mySteps;
}
for (i=0; i< mySteps ; i++)
{
digitalWrite(stepperPins, stepBits[i % stepBits.length]);
//then we need to wait before sending next command
wait(1); //some motors might need a longer delay
}
}
function wait(ms){
var d = new Date();
var d2 = null;
do { d2 = new Date(); }
while(d2-d < ms);
}
I have made a setWatch function to look for a button press to then start a function
setWatch(function () {
action goes here
}, BTN2, {
repeat : true,
edge : "rising"
});
I am looking for the stepper motor to do a full 360 turn in 6 minutes. For the stepper to do a full 360 turn it's 350 steps so a 1030ms wait between each step (360000/350?). So when I press BTN2 the stepper spins 360 degrees over a 6 minute time span.
I am unsure how to combine the two, can any of you help me out?
If I do this:
setWatch(function () {
motorStep(350);
}, BTN2, {
repeat : true,
edge : "rising"
});
How would I code the time required to do the full action?