Yes, I'm going to use 7 steppers in my project. It is not only about steppers, OOP is easiest way to build application for me.
By taking advantage @Gordon's code I have build my OOP like this; The way below is easy to read and understand the code for me.
modules/stepperClass.js
exports.stepperClass = function (p1, p2, p3, p4) { var step = 0; var steps = [0b0001, 0b0011, 0b0010, 0b0110, 0b0100, 0b1100, 0b1000, 0b1001]; var stepperPins = [p4, p3, p2, p1]; this.writeStep = function () { step++; digitalWrite(stepperPins, steps[step % steps.length]); }; this.stop = function () { digitalWrite(stepperPins[0], LOW); digitalWrite(stepperPins[1], LOW); digitalWrite(stepperPins[2], LOW); digitalWrite(stepperPins[3], LOW); }; this.doStep = function (cnt) { for (i = 0; i < cnt; i++) { x = 0; while (x < 10) x++;//delay a little bit this.writeStep(); } this.stop(); };
projects/main.js
var stepperClass=require('stepperClass').stepperClass; stepper1=new stepperClass(A1,A2,A3,A4); stepper2=new stepperClass(B1,B2,B3,B4); stepper3=new stepperClass(C1,C2,C3,C4); stepper1.doStep(100); .... .... ....
@fobus started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yes, I'm going to use 7 steppers in my project. It is not only about steppers, OOP is easiest way to build application for me.
By taking advantage @Gordon's code I have build my OOP like this; The way below is easy to read and understand the code for me.