diff options
| author | Donald Delmar Davis <don@suspectdevices.com> | 2013-05-24 16:40:10 -0700 |
|---|---|---|
| committer | Donald Delmar Davis <don@suspectdevices.com> | 2013-05-24 16:40:10 -0700 |
| commit | dced1ddb7316c5b5911f6f78d9f434a739a7d01f (patch) | |
| tree | 59dcd1cab8371772edbaee8a7d7edc0c6be25f1a /RetoolingForOpenSprints/NewClock | |
| parent | 44c5fd954ec6c4ef5028e2b4bfb88cd4cdf1632a (diff) | |
Initial commit.
Diffstat (limited to 'RetoolingForOpenSprints/NewClock')
| -rw-r--r-- | RetoolingForOpenSprints/NewClock/NewClock/NewClock.ino | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/RetoolingForOpenSprints/NewClock/NewClock/NewClock.ino b/RetoolingForOpenSprints/NewClock/NewClock/NewClock.ino new file mode 100644 index 0000000..bb44efe --- /dev/null +++ b/RetoolingForOpenSprints/NewClock/NewClock/NewClock.ino @@ -0,0 +1,85 @@ + +/* + * ##### requires modified + * + * 5.9222222 steps per degree. + * too much error. + * + */ + +#include <Stepper.h> +#define MIN_MILLIS_PER_STEP 3 +#define STEPPER_STEPS 200 +#define STEPS_PER_REVOLUTION 2132 // for your motor +#define INBUFFERLENGTH 100 +char inbuffer[INBUFFERLENGTH]; +int bufferIndex; +int yellowGoal=0; +int blueGoal=0; +int yellowPosition=0; +int bluePosition=0; +int stepCount = 0; // number of steps the motor has taken +long int lastStepMillis; + +Stepper blue(STEPPER_STEPS, 8,9,10,11,1); +Stepper yellow(STEPPER_STEPS, 2,3,4,5,1); + +void setup() { + // initialize the serial port: + Serial.begin(115200); +} + +void loop() { + int target; + while (Serial.available()) { + // get the new byte: + char inChar = (char)Serial.read(); + // add it to the inputString: + if (bufferIndex<INBUFFERLENGTH) + inbuffer[bufferIndex++]=inChar; + if (inChar == '\n') { + inbuffer[bufferIndex]=0; + if ((inbuffer[0]=='d') && bufferIndex>3) { + target=atoi(inbuffer+3); + if (target>STEPS_PER_REVOLUTION)target=STEPS_PER_REVOLUTION; + if (inbuffer[1]=='1') { + blueGoal=target;//analogWrite(MOTOR1PWM,bike1speed); + Serial.println(inbuffer+3); + Serial.print("blueGoal="); Serial.println(blueGoal); + Serial.print("bluePosition="); Serial.println(bluePosition); + } else { + yellowGoal=target;//analogWrite(MOTOR2PWM,bike1speed); + } + } else if (inbuffer[0]=='v') { + Serial.println("RaceClock 0.1"); + Serial.flush(); + } else if (inbuffer[0]=='s') { + blueGoal=yellowGoal=STEPS_PER_REVOLUTION; + } + + bufferIndex=0; //reset input + + } + } + if ((millis()-lastStepMillis)>MIN_MILLIS_PER_STEP){ + if ((blueGoal>bluePosition) && (bluePosition<=STEPS_PER_REVOLUTION)){ + blue.step(-1); + bluePosition++; + } + + if ((yellowGoal>yellowPosition) && (yellowPosition<=STEPS_PER_REVOLUTION)) { + yellow.step(-1); + yellowPosition++; + } + lastStepMillis=millis(); + } + if ((bluePosition==STEPS_PER_REVOLUTION)&&(blueGoal==bluePosition)){ + blueGoal=bluePosition=0; + } + if ((yellowPosition==STEPS_PER_REVOLUTION)&&(yellowGoal==yellowPosition)){ + yellowGoal=yellowPosition=0; + } + +} + + |
