Browse Source

plop

master
Dashie der otter 1 month ago
parent
commit
ab551b7117
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755
1 changed files with 30 additions and 30 deletions
  1. 30
    30
      read_plotter/read_plotter.ino

+ 30
- 30
read_plotter/read_plotter.ino View File

@@ -6,8 +6,8 @@
#define PIN_X 2
#define PIN_Y 0

# Same as configured in the scope
#define PLOT_TIMER 100
# configured in the scope / 4
#define PLOT_TIMER 25

# Limit to consider the pen UP or DOWN
# Set the Pen DOWN to "1", the Z_LIMIT should be greater than when the
@@ -15,53 +15,53 @@
#define Z_LIMIT 20
# END Config

# up false, down true
bool pen_active = false;
enum pen { PEN_UNK, PEN_UP, PEN_DOWN }

int pen_state = PEN_UNK;

void setup() {
Serial.begin(115200);
analogReference(INTERNAL); // 1.1V reference
Serial.print("#REM Started with AREF INTERNAL, timer of ");
Serial.println(PLOT_TIMER);
Serial.println("#WAIT Waiting to pen down");
Serial.println("IN;");
Serial.println("SP 1;");

# Create the plotting timer
MsTimer2::set(PLOT_TIMER, readXY);
MsTimer2::start();
}

void readXY() {
# If Z get under the Z_LIMIT, stop the timer
int Z = analogRead(PIN_Z);
int new_pen_state = PEN_UNK;

// Read pen position
if (Z < Z_LIMIT) {
pen_active = false;
MsTimer2::stop();
Serial.println("#PENUP Pen UP");
return;
new_pen_state = PEN_UP;
} else if (Z >= Z_LIMIT) {
new_pen_state = PEN_DOWN;
}

// output pen state if changed
if (new_pen_state != pen_state) {
if ( pen_state == PEN_UP ) {
Serial.println("PU;");
} else {
Serial.println("PD;");
}
}
// output position absolute
int X = analogRead(PIN_X);
int Y = analogRead(PIN_Y);
Serial.print("PA ");
Serial.print(X);
Serial.print(";");
Serial.println(Y);
Serial.print(",");
Serial.print(Y);
Serial.println(";");
}

void loop() {
if (pen_active) {
return; // Do nothing if pen is active
}
# Else, wait until we detect that the pen (Z) is higher than Z_LIMIT
while(true) {
int Z = analogRead(PIN_Z);
if (Z >= Z_LIMIT) {
Serial.println("#PENDOWN Pen went down");
pen_active = true;
break;
}
}

# Pen went UP
pen_active = true;
MsTimer2::start();
return; // Do nothing
}

Loading…
Cancel
Save