#include <Stepper.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ts = Adafruit_FT6206();
// The display also uses hardware SPI, plus #51 & #52
#define TFT_CS 51
#define TFT_DC 2
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
const int tStepsPerRev = 200;
// initialize the stepper library on pins 8 through 11:
Stepper spool(stepsPerRevolution, 8, 9, 10, 11);
Stepper traverse(tStepsPerRev, 4,5,6,7);
int stepCount = 0; // # of steps for the spool to take
int layerCount = 0; // counter for # of wire layers
int SRCount = 0; //
int tCount = 0; //
int spoolDia = 11;
int ratio = spoolDia/0.5; // drive ratio
int revCount = 0; // # of spool stepper revs
int steps = ratio*stepsPerRevolution; // # of steps for 1 spool rotaion
int tSteps = 18.4; // # of steps traverse needs to move
int wireLength = 500; // input desired length of wire
int reqRevs = wireLength/(2*PI*spoolDia); // # of revs to get needed wire length
int complete =0;
#define FRAME_X 210
#define FRAME_Y 180
#define FRAME_W 100
#define FRAME_H 50
void setup() {
// initialize the serial port:
spool.setSpeed(300);
Serial.begin(9600);
Serial.println(F("Spool Splitter"));
Serial.print("length / required revs:");
Serial.println(reqRevs);
tft.begin();
if (! ts.begin(1)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
Serial.println("Capacitive touchscreen started");
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_GREEN);
tft.setCursor(FRAME_X + 6 , FRAME_Y + (FRAME_H/2));
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("ON");
}
void loop() {
// Wait for a touch
if (! ts.touched()) {
return;
}
if(revCount < reqRevs){
// step one step:
spool.step(steps);
Serial.print("spoolRev:");
Serial.println(SRCount);
SRCount++;
revCount++;
traverse.step(tSteps);
//Serial.print("steps:");
//Serial.println(tCount);
tCount++;
if (SRCount > 5){
layerCount++;
SRCount = 0;
tSteps = -tSteps;
}
}else{
Serial.print("COMPLETE");
return;
//complete = 1;
}
}