Pen Decorator – coding the basic functions

The servo used to raise and lower the drill, sits on the back of the cantilever. A single arm on the servo will lever the platform down (by pushing up against a stabilizer bar). So there are a pair of actions that will be created, one to “raise” the drill and one to “lower” the drill. I’m calling these operations “DrillUp” and “DrillDown” in this phase. Additionally, I want to have some kind of feedback available via the display, so I will add an action to write a message to display ( and a bit of extra logic to keep duplicates out – the write to the LCD interferes with the timing of the drive motors)

void lcdMsg(int line, String txt) {
   if (line == 1) {
     if (txt == otxt) return;
      otxt = txt;
   else {
      if (txt == otxt2) return;
      otxt2 = txt;
   lcd.print(" ");
void DrillUp() {
   lcdMsg(1,"DRILL UP");
  isDrillDown = false;
void DrillDown() {
   lcdMsg(1,"DRILL DOWN");
   isDrillDown = true;

I also need to have actions defined to actually execute running a pattern (RunDrill) and a way to rewind everything back to a starting point. And speaking of a starting point, there needs to be a mechanism for identifying the ends of the pen for the purposes of identifying a start and end point. Since the drive screw is 20 turns per inch, I know that a 4 inch pen would need 80 turns — however, I also have to figure out where the pen starts to begin counting from. Oh, and I also need to make sure that I dont try to run the carriage through either side of the carriage box itself. Finally, I need to have the definitions set up for each of the patterns that I plan to support:

Spiral (left)
Spiral (right)
Sinewave (vary the amplitude, vary the frequency)
ZigZag (vary the amplitude, vary the frequency)


So after all that, I’ve got the following routines I want to create:

Rewind() {}
GetDomain() {} // figure out how wide the carriage box is, 
               // so we don't run into the sides
GetExtents() {} // set the start and end position of the pen blank
RunDrill() {}

And I also need to define a mechanism to set the instructions on each of the patterns. That’s likely to be a set of data that is used to load the settings at the start of running the Drill. The elements I need when using the AccelStepper library will be:

maxSpeed   // the fully accelerated speed of the axis

accel      // the acceleration/deceleration speed stepup/stepdown 
           // I plan to use this to simulate the sine wave form

position   // the calculated steps that need to be run 
           // (inches * revelutions_per_inch * steps_per_revolution)

oscillate  // the action to perform after reaching the end position 
           // true - run back and forth
           // false - stop at the end




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s