/**
This code was hacked together by Robi Akerley-McKee for some peplums we needed to cut for some cossack jackets. This is a calculator for Full Circle Skirts. Uses minimum amount of fabric. This is generic in that it considers the waist a perfect circle. For faire skirts and coat peplums this really doesn't matter... It would be noticable on really short skirts, on anything longer than the knee it is not noticeable.
Arduino Uno R3 clones on ebay can be had for less than $4 with free shipping. The LCD with keypads can be found for less than $3 http://www.ebay.com/itm/LCD-1602-Keypad-Shield-For-Arduino-Due-UNO-R3-PANTALLA-AZUL-BUTTONS-Hot-/122413950300
I originally wrote a spreadsheet to do this. I haven't found a good spot to save it. I had an extra Arduino uno and LCD from a GPS project so I put this together.
*/
// #include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define DEBUG 0
// SoftwareSerial mySerial(19, 18); // RX, TX
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// these are the start up defaults, you can change them here... so it comes up with your waistline and preferred drop
//
// This is your fabric before folding. Normal is 45". Faire people might be more used to 54" or 60" upholstery fabric.
float Fabric=45;
// This is the normal Ease used at the waist for just about everyone. If your waist is really small you
// might consider lowering this number. If you have a large 50+ you might consider raising it.
float Ease=2;
// This is standard 5/8" seam allowance in decimal inches -- I divide it by 1000 later.
float Seam=625;
// This is the starting Waist size. you can change it for your waist if you would like to.
float Waist=30;
// This is the drop, straight down from the waist. Program accounts for seam allowances.
float Drop=22;
// shouldn't need to change anything past here.
//
int VOID = 1;
float float10 = 10;
//int rxPin = 19; // RX pin
//int txPin = 18; // TX pin
//int DayLight = -8;
//int byteGPS = -1;
//char format = "123456787899";
int counter1 = 120; // This set the timing between the screens
int counter2; // used later
//int offsets[13];
int ReadKey;
float s2, s1;
float d90,d60,d45,d30,sa90,sa60,sa45,sa30,h,sa;
float WaistRadius;
float Folded;
const float pi=3.14159265458979;
char buf[310] = "";
char buf2[10] = "";
char buf3[10] = "";
//int first = 1;
byte Gore30[8] = {
B00000,
B10000,
B10000,
B11000,
B11000,
B11100,
B11100,
B00000
};
byte Gore60[8] = {
B10000,
B11000,
B10110,
B10001,
B11110,
B00000,
B00000,
B00000
};
byte Gore45[8] = {
B00000,
B11000,
B10010,
B10100,
B11000,
B10000,
B00000,
B00000
};
byte Gore90[8] = {
B00000,
B00000,
B11111,
B10001,
B10000,
B10010,
B11000,
B00000
};
char CRLF[3] = {13,10,0};
// Keys AnalogRead(0);
const int KeySelect = 650;
const int KeyLeft = 409;
const int KeyRight = 0;
const int KeyUp = 100;
const int KeyDown = 255;
// select 600-650
// left 350-500
// right 0
// up 50-200
// down 201-349
int Key, KeyCount, LastKey;
int backLight=125;
int BackLightPin = 10;
int ReadTheKey() {
Key = analogRead(0);
if (Key < 900 ) {
if(abs(LastKey-Key)<30) {
if(++KeyCount>4) {
Serial.print("Key : ");
Serial.println(Key);
KeyCount=0;
return Key;
}
//} else {
// KeyCount=0;
Serial.print(" KeyCount : ");
Serial.print(KeyCount);
Serial.print("Key : ");
Serial.println(Key);
return 1023;
}
}
LastKey=Key;
return 1023;
}
// this is the generic routine for entering the numbers
float GetInput(float Work, float TheMin, float TheMax, int Column, int Row, int Length, float Step, int Digit, int Decimals) {
int CurrentColumn=0;
do {
ReadKey = ReadTheKey();
if(abs(ReadKey-KeyUp)<30 && (Work < TheMax)) {
Work += Step;
} else if(abs(ReadKey-KeyDown)<30 && (Work > TheMin)) {
Work -= Step;
} else if(abs(ReadKey-KeyRight)<30 && Work < (TheMax-(10 *Step))) {
Work += (10 *Step);
} else if(abs(ReadKey-KeyLeft)<30 && Work > (TheMin+(10 *Step))) {
Work -= (10 *Step);
}
if(Work<10) {
CurrentColumn=2;
} else if (Work < 100) {
CurrentColumn=1;
} else CurrentColumn=0;
lcd.setCursor(Column+CurrentColumn,Row);
dtostrf(Work,Digit,Decimals,buf2);
lcd.print(buf2);
delay(25);
Serial.print("ReadKey ");
Serial.print(ReadKey);
Serial.print(" KeyCount ");
Serial.println(KeyCount);
} while (abs(ReadKey-KeySelect)>30);
do {
ReadKey = analogRead(0);
Serial.print("ReadKey ");
Serial.print(ReadKey);
Serial.println("Key Release ===============================================");
delay(50);
} while (ReadKey<800);
return Work;
}
// When you get an answer, using the up and down buttons you can adjust the screen brightness
void SetBackLight() {
//do {
ReadKey= ReadTheKey();
if(ReadKey<1023) {
if(abs(ReadKey-KeyUp)<30 ) {
if(backLight<255) backLight += 5;
KeyCount=0;
Serial.println(backLight);
} else if(abs(ReadKey-KeyDown)<30 ) {
if(backLight>0) backLight -= 5;
KeyCount=0;
Serial.println(backLight);
}
analogWrite(BackLightPin,backLight);
}
// } while ( abs(Key-KeySelect)>30);
}
void WaitKey() {
Serial.println("WaitKey");
delay(2000);
KeyCount=0;
do {
Key = analogRead(0);
if(Key<800) KeyCount++; else KeyCount=0;
delay(50);
} while(KeyCount<4);
}
/**
Setup display and gps
*/
void setup() {
Serial.begin(9600);
lcd.createChar(0,Gore90);
lcd.createChar(1,Gore60);
lcd.createChar(2,Gore45);
lcd.createChar(3,Gore30);
// this is setting the backlight pin
pinMode(BackLightPin,OUTPUT);
analogWrite(BackLightPin,80);
lcd.begin(16, 2);
lcd.clear();
Serial.println("Gore Calc");
lcd.print(" Gore Calc");
lcd.setCursor(0,1);
lcd.print("Fabric:");
// GetInput( Work, TheMin, TheMax, Column, Row, Length, Step, Digit, Decimals)
Serial.println("Fabric");
Fabric = GetInput(Fabric,4,999,8,1,3,.5,4,1);
lcd.setCursor(0,1);
lcd.print("Seam : 0.");
Serial.println("Seam");
Seam = GetInput(Seam,4,999,10,1,3,1,1,4);
Seam = Seam;
lcd.setCursor(0,1);
lcd.print("Ease : ");
Serial.println("Ease");
Ease = GetInput(Ease,0,9,11,1,3,.1,2,1);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("F");
lcd.print(Fabric);
lcd.setCursor(4,0);
lcd.print(" S");
dtostrf(Seam/1000,1,4,buf2);
lcd.print(buf2);
lcd.setCursor(11,0);
lcd.print(" E");
dtostrf(Ease,1,3,buf2);
lcd.print(buf2);
//lcd.print(Ease);
//WaitKey();
lcd.setCursor(0,1);
lcd.print("Waist : ");
Serial.println("Waist");
Waist = GetInput(Waist,20,90,12,1,3,.5,3,0);
lcd.setCursor(0,1);
lcd.print("Drop : ");
Serial.println("Drop");
Drop = GetInput(Drop,4,60,10,1,3,.25,3,2);
lcd.setCursor(0,1);
lcd.print("W");
dtostrf(Waist,4,1,buf2);
lcd.print(buf2);
lcd.setCursor(7,1);
lcd.print(" D");
dtostrf(Drop,4,1,buf2);
lcd.print(buf2);
//WaitKey();
WaistRadius = Waist/pi/2;
s1 = Seam / 1000;
s2 = 2 * Seam / 1000;
d90 = (Waist + ( 6 * s1))/pi/2;
d60 = (Waist + ( 8 * s1))/pi/2;
d45 = (Waist + (12 * s1))/pi/2;
d30 = (Waist + (16 * s1))/pi/2;
sa90 = (d90+Drop+s1)*1;
sa60 = (d60+Drop+s1)*.866;
sa45 = (d45+Drop+s1)*.7071;
sa30 = (d30+Drop+s1)*.5;
Folded=(Fabric+s1)/2;
h = (sa90<Folded) ? 0 : 1;
h = (sa60<Folded) ? 1 : 2;
h = (sa45<Folded) ? 2 : 3;
h = (sa30<Folded) ? 3 : 3;
counter2=counter1;
}
/**
Main loop
*/
void loop() {
//lcd.clear();
Serial.println(analogRead(0));
// select 600-650
// left 350-500
// right 0
// up 50-200
// down 201-349
// C R
if(counter1==0) {
#if DEBUG > 0
Serial.println("Before Clear");
#endif
lcd.clear();
lcd.setCursor(0,0);
lcd.print("F");
dtostrf(Folded,3,3,buf2);
lcd.print(buf2);
lcd.setCursor(4,0);
lcd.print(" S");
Serial.println("dtofstrf Seam");
dtostrf(Seam/1000,1,4,buf2);
lcd.print(buf2);
lcd.setCursor(11,0);
lcd.print(" E");
Serial.print("Ease ");
dtostrf(Ease,1,3,buf2);
lcd.print(buf2);
lcd.setCursor(0,1);
lcd.print("Gore W: ");
dtostrf(sa,3,3,buf2);
lcd.print(buf2);
Serial.println(buf2);
//delay(3000);
}
if(counter1==counter2) {
lcd.setCursor(0,0);
dtostrf(d90,3,1,buf2);
Serial.print(buf2);
Serial.print(" ");
dtostrf(Drop,3,1,buf2);
Serial.print(buf2);
Serial.print(" ");
dtostrf(s1,1,3,buf2);
Serial.print(buf2);
Serial.print(" Waist Radius");
// = /pi/2;
dtostrf(WaistRadius,3,3,buf2);
Serial.print(buf2);
Serial.print(" waist ");
dtostrf(Waist,1,3,buf2);
Serial.println(buf2);
Serial.print(" Folded Fabric + Seam Allowance 1 : ");
dtostrf(Folded,3,3,buf2);
Serial.println(buf2);
Serial.print("d90 + Drop + s1 :");
dtostrf((d90+Drop+s1),3,3,buf2);
Serial.print(buf2);
Serial.print(" L ");
Serial.println(((d90+Drop+s1)>Folded) ? "Bigger" : "Fits") ;
Serial.print("d60 + Drop + s1 :");
dtostrf((d60+Drop+s1)*.866,3,3,buf2);
Serial.print(buf2);
Serial.print(" L ");
Serial.println(((d60+Drop+s1)*.866>Folded) ? "Bigger" : "Fits") ;
Serial.print("d45 + Drop + s1 :");
dtostrf((d45+Drop+s1)*.7071,3,3,buf2);
Serial.print(buf2);
Serial.print(" L ");
Serial.println(((d45+Drop+s1)*.7071>Folded) ? "Bigger" : "Fits") ;
Serial.print("d30 + Drop + s1 :");
dtostrf((d30+Drop+s1)*.5,3,3,buf2);
Serial.print(buf2);
Serial.print(" L ");
Serial.println(((d30+Drop+s1)*.5>Folded) ? "Bigger" : "Fits") ;
lcd.setCursor(0,0);
lcd.print("Folded ");
dtostrf(Folded,3,2,buf2);
lcd.print(buf2);
lcd.print(" ");
if((d90+Drop+s1)<Folded) {
lcd.clear();
sa=sa90;
Serial.println("in 90");
lcd.setCursor(0,0);
lcd.setCursor(13,0);
lcd.print("P2n");
lcd.setCursor(0,1);
lcd.print("90 w:");
dtostrf(d90-s1,3,1,buf2);
lcd.print(buf2);
lcd.setCursor(8,1);
lcd.print(" h:");
dtostrf(d90+Drop+s1,3,1,buf2);
lcd.print(buf2);
// fits at 90 degrees
} else if(d60+Drop+s1*.866<Folded) {
Serial.println("in 60");
// fits at 60 degrees
sa=sa60;
lcd.setCursor(13,0);
lcd.print("C3n");
lcd.setCursor(0,1);
lcd.print("60 w:");
dtostrf(d60-s1,3,1,buf2);
lcd.print(buf2);
lcd.setCursor(8,1);
lcd.print(" h:");
dtostrf(d60+Drop+s1,3,1,buf2);
lcd.print(buf2);
} else if((d45+Drop+s1)*0.7071<Folded) {
// fits at 45 degrees
sa=sa45;
Serial.println("in 45");
lcd.setCursor(13,0);
lcd.print("C4n");
lcd.setCursor(0,1);
lcd.print("45 w:");
dtostrf(d45-s1,2,1,buf2);
lcd.print(buf2);
lcd.setCursor(8,1);
lcd.print("h:");
dtostrf(d45+Drop+s1,3,1,buf2);
lcd.print(buf2);
} else if((d30+Drop+s1)*.5<Folded) {
sa=sa30;
// fits at 30 degrees
Serial.println("in 30");
lcd.setCursor(13,0);
lcd.print("C6n");
lcd.setCursor(0,1);
lcd.print("30 w:");
dtostrf(d30-s1,3,1,buf2);
lcd.print(buf2);
lcd.setCursor(8,1);
lcd.print("h:");
dtostrf(d30+Drop+s1,3,1,buf2);
lcd.print(buf2);
}
}
// delay(3000);
Serial.print(counter1);
Serial.println("COUNTER1 ======================== End Loop");
lcd.setCursor(15,1);
lcd.write(byte(h));
if(counter1++ > (counter2*2)) counter1=0;
SetBackLight();
delay(25);
}
Comments