Advertisement
RobiSydney

Skirt Gore Calculator 1602 LCD Arduino UNO.ino

May 26th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.68 KB | None | 0 0
  1. /**
  2.    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.
  3.  
  4. 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
  5.  
  6. 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.
  7.  
  8. */
  9. // #include <SoftwareSerial.h>
  10. #include <LiquidCrystal.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <math.h>
  14. #define DEBUG 0
  15. // SoftwareSerial mySerial(19, 18); // RX, TX
  16. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  17.  
  18. // these are the start up defaults, you can change them here... so it comes up with your waistline and preferred drop
  19. //
  20.  
  21. // This is your fabric before folding. Normal is 45".  Faire people might be more used to 54" or 60" upholstery fabric.
  22. float Fabric=45;
  23.  
  24. // This is the normal Ease used at the waist for just about everyone.  If your waist is really small you
  25. // might consider lowering this number.  If you have a large 50+ you might consider raising it.
  26. float Ease=2;
  27.  
  28. // This is standard 5/8" seam allowance in decimal inches -- I divide it by 1000 later.
  29. float Seam=625;
  30.  
  31. // This is the starting Waist size.  you can change it for your waist if you would like to.
  32. float Waist=30;
  33.  
  34. // This is the drop, straight down from the waist. Program accounts for seam allowances.
  35. float Drop=22;
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. // shouldn't need to change anything past here.
  43. //
  44.  
  45.  
  46.  
  47.  
  48.  
  49. int VOID = 1;
  50. float float10 = 10;
  51. //int rxPin = 19; // RX pin
  52. //int txPin = 18; // TX pin
  53. //int DayLight = -8;
  54. //int byteGPS = -1;
  55. //char format = "123456787899";
  56. int counter1 = 120; // This set the timing between the screens
  57. int counter2; // used later
  58. //int offsets[13];
  59. int ReadKey;
  60. float s2, s1;
  61. float d90,d60,d45,d30,sa90,sa60,sa45,sa30,h,sa;
  62. float WaistRadius;
  63. float Folded;
  64. const float pi=3.14159265458979;
  65.  
  66.  
  67. char buf[310] = "";
  68. char buf2[10] = "";
  69. char buf3[10] = "";
  70. //int first = 1;
  71.  
  72. byte Gore30[8] = {
  73.   B00000,
  74.   B10000,
  75.   B10000,
  76.   B11000,
  77.   B11000,
  78.   B11100,
  79.   B11100,
  80.   B00000
  81.  
  82. };
  83. byte Gore60[8] = {
  84.   B10000,
  85.   B11000,
  86.   B10110,
  87.   B10001,
  88.   B11110,
  89.   B00000,
  90.   B00000,
  91.   B00000
  92.  
  93. };
  94. byte Gore45[8] = {
  95.   B00000,
  96.   B11000,
  97.   B10010,
  98.   B10100,
  99.   B11000,
  100.   B10000,
  101.   B00000,
  102.   B00000
  103.  
  104. };
  105. byte Gore90[8] = {
  106.   B00000,
  107.   B00000,
  108.   B11111,
  109.   B10001,
  110.   B10000,
  111.   B10010,
  112.   B11000,
  113.   B00000
  114.  
  115. };
  116.  
  117. char CRLF[3] = {13,10,0};
  118.  
  119.  
  120.  
  121.  
  122. // Keys AnalogRead(0);
  123. const int KeySelect = 650;
  124. const int KeyLeft = 409;
  125. const int KeyRight = 0;
  126. const int KeyUp = 100;
  127. const int KeyDown = 255;
  128. // select 600-650
  129. // left 350-500
  130. // right 0
  131. // up 50-200
  132. // down 201-349
  133.  
  134. int Key, KeyCount, LastKey;
  135. int backLight=125;
  136. int BackLightPin = 10;
  137.  
  138.  
  139. int ReadTheKey() {
  140.   Key = analogRead(0);
  141. if (Key < 900 )  {
  142.   if(abs(LastKey-Key)<30) {
  143.     if(++KeyCount>4) {
  144.       Serial.print("Key : ");
  145.       Serial.println(Key);
  146.       KeyCount=0;
  147.       return Key;
  148.     }
  149.   //} else {
  150.   //  KeyCount=0;
  151.       Serial.print(" KeyCount : ");
  152.       Serial.print(KeyCount);
  153.       Serial.print("Key : ");
  154.       Serial.println(Key);
  155.     return 1023;
  156.   }
  157. }
  158.   LastKey=Key;
  159.   return 1023;  
  160.  
  161. }
  162.  
  163. // this is the generic routine for entering the numbers
  164.  
  165. float GetInput(float Work, float TheMin, float TheMax, int Column, int Row, int Length, float Step, int Digit, int Decimals) {
  166.   int CurrentColumn=0;
  167.  
  168.   do {
  169.     ReadKey = ReadTheKey();
  170.     if(abs(ReadKey-KeyUp)<30 && (Work < TheMax)) {
  171.       Work += Step;
  172.     } else if(abs(ReadKey-KeyDown)<30 && (Work > TheMin)) {
  173.       Work -= Step;
  174.     } else if(abs(ReadKey-KeyRight)<30 && Work < (TheMax-(10 *Step))) {
  175.       Work += (10 *Step);
  176.     } else if(abs(ReadKey-KeyLeft)<30 && Work > (TheMin+(10 *Step))) {
  177.       Work -= (10 *Step);
  178.     }
  179.     if(Work<10) {
  180.       CurrentColumn=2;
  181.     } else if (Work < 100) {
  182.       CurrentColumn=1;
  183.     } else CurrentColumn=0;
  184.     lcd.setCursor(Column+CurrentColumn,Row);  
  185.     dtostrf(Work,Digit,Decimals,buf2);
  186.     lcd.print(buf2);
  187.     delay(25);    
  188.     Serial.print("ReadKey ");
  189.     Serial.print(ReadKey);
  190.     Serial.print(" KeyCount  ");
  191.     Serial.println(KeyCount);
  192.   } while (abs(ReadKey-KeySelect)>30);
  193.   do {
  194.     ReadKey = analogRead(0);
  195.     Serial.print("ReadKey   ");
  196.     Serial.print(ReadKey);
  197.     Serial.println("Key Release ===============================================");
  198.     delay(50);
  199.   } while (ReadKey<800);
  200.   return Work;
  201. }
  202.  
  203. // When you get an answer,  using the up and down buttons you can adjust the screen brightness
  204.  
  205. void SetBackLight() {
  206.   //do {
  207.     ReadKey= ReadTheKey();
  208.     if(ReadKey<1023) {
  209.       if(abs(ReadKey-KeyUp)<30 ) {
  210.         if(backLight<255) backLight += 5;
  211.         KeyCount=0;
  212.         Serial.println(backLight);
  213.       } else if(abs(ReadKey-KeyDown)<30 ) {
  214.         if(backLight>0) backLight -= 5;
  215.         KeyCount=0;  
  216.         Serial.println(backLight);
  217.       }
  218.        
  219.       analogWrite(BackLightPin,backLight);
  220.     }
  221.  // } while (  abs(Key-KeySelect)>30);
  222.  
  223. }
  224.  
  225.  
  226. void WaitKey() {
  227.   Serial.println("WaitKey");
  228.  
  229.   delay(2000);
  230.   KeyCount=0;
  231.   do {
  232.     Key =  analogRead(0);
  233.     if(Key<800) KeyCount++; else KeyCount=0;
  234.     delay(50);
  235.   } while(KeyCount<4);
  236.  
  237. }
  238.  
  239. /**
  240.    Setup display and gps
  241. */
  242. void setup() {
  243.   Serial.begin(9600);
  244.   lcd.createChar(0,Gore90);
  245.   lcd.createChar(1,Gore60);
  246.   lcd.createChar(2,Gore45);
  247.   lcd.createChar(3,Gore30);
  248. // this is setting the backlight pin
  249.     pinMode(BackLightPin,OUTPUT);
  250.     analogWrite(BackLightPin,80);  
  251.   lcd.begin(16, 2);
  252.   lcd.clear();
  253.   Serial.println("Gore Calc");
  254.   lcd.print("    Gore Calc");
  255.  
  256.  
  257. lcd.setCursor(0,1);
  258. lcd.print("Fabric:");
  259. // GetInput( Work, TheMin, TheMax, Column, Row, Length, Step, Digit, Decimals)
  260. Serial.println("Fabric");
  261. Fabric = GetInput(Fabric,4,999,8,1,3,.5,4,1);
  262. lcd.setCursor(0,1);
  263. lcd.print("Seam    : 0.");
  264. Serial.println("Seam");
  265. Seam = GetInput(Seam,4,999,10,1,3,1,1,4);
  266. Seam = Seam;
  267.  
  268. lcd.setCursor(0,1);
  269. lcd.print("Ease       : ");
  270. Serial.println("Ease");
  271.  
  272. Ease = GetInput(Ease,0,9,11,1,3,.1,2,1);
  273.   lcd.setCursor(0,0);
  274.   lcd.print("                ");
  275.   lcd.setCursor(0,1);
  276.   lcd.print("                ");
  277. lcd.setCursor(0,0);
  278. lcd.print("F");
  279. lcd.print(Fabric);
  280. lcd.setCursor(4,0);
  281. lcd.print(" S");
  282. dtostrf(Seam/1000,1,4,buf2);
  283. lcd.print(buf2);
  284. lcd.setCursor(11,0);
  285. lcd.print(" E");
  286. dtostrf(Ease,1,3,buf2);
  287. lcd.print(buf2);
  288. //lcd.print(Ease);
  289. //WaitKey();
  290. lcd.setCursor(0,1);
  291. lcd.print("Waist   : ");
  292. Serial.println("Waist");
  293. Waist = GetInput(Waist,20,90,12,1,3,.5,3,0);
  294. lcd.setCursor(0,1);
  295. lcd.print("Drop    : ");
  296. Serial.println("Drop");
  297. Drop = GetInput(Drop,4,60,10,1,3,.25,3,2);
  298. lcd.setCursor(0,1);
  299. lcd.print("W");
  300. dtostrf(Waist,4,1,buf2);
  301. lcd.print(buf2);
  302. lcd.setCursor(7,1);
  303. lcd.print(" D");
  304. dtostrf(Drop,4,1,buf2);
  305. lcd.print(buf2);
  306. //WaitKey();
  307.  
  308. WaistRadius = Waist/pi/2;
  309. s1 = Seam / 1000;
  310. s2 = 2 * Seam / 1000;
  311. d90 = (Waist + ( 6 * s1))/pi/2;
  312. d60 = (Waist + ( 8 * s1))/pi/2;
  313. d45 = (Waist + (12 * s1))/pi/2;
  314. d30 = (Waist + (16 * s1))/pi/2;
  315. sa90 = (d90+Drop+s1)*1;
  316. sa60 = (d60+Drop+s1)*.866;
  317. sa45 = (d45+Drop+s1)*.7071;
  318. sa30 = (d30+Drop+s1)*.5;
  319.  
  320. Folded=(Fabric+s1)/2;
  321. h = (sa90<Folded) ? 0 : 1;
  322. h = (sa60<Folded) ? 1 : 2;
  323. h = (sa45<Folded) ? 2 : 3;
  324. h = (sa30<Folded) ? 3 : 3;
  325. counter2=counter1;
  326. }
  327.  
  328.  
  329.  
  330. /**
  331.    Main loop
  332. */
  333. void loop() {
  334.   //lcd.clear();
  335. Serial.println(analogRead(0));
  336. // select 600-650
  337. // left 350-500
  338. // right 0
  339. // up 50-200
  340. // down 201-349
  341. //            C R
  342.  
  343. if(counter1==0) {
  344. #if DEBUG > 0
  345.   Serial.println("Before Clear");
  346. #endif
  347.     lcd.clear();
  348.     lcd.setCursor(0,0);
  349.     lcd.print("F");
  350.     dtostrf(Folded,3,3,buf2);
  351.     lcd.print(buf2);
  352.     lcd.setCursor(4,0);
  353.     lcd.print(" S");
  354.   Serial.println("dtofstrf Seam");
  355.     dtostrf(Seam/1000,1,4,buf2);
  356.     lcd.print(buf2);
  357.     lcd.setCursor(11,0);
  358.     lcd.print(" E");
  359.   Serial.print("Ease ");
  360.     dtostrf(Ease,1,3,buf2);
  361.     lcd.print(buf2);
  362.     lcd.setCursor(0,1);
  363.     lcd.print("Gore W: ");
  364.        dtostrf(sa,3,3,buf2);
  365.     lcd.print(buf2);
  366.   Serial.println(buf2);
  367.   //delay(3000);
  368. }
  369.  
  370. if(counter1==counter2) {  
  371.   lcd.setCursor(0,0);
  372.     dtostrf(d90,3,1,buf2);
  373.   Serial.print(buf2);
  374.   Serial.print(" ");
  375.     dtostrf(Drop,3,1,buf2);
  376.   Serial.print(buf2);
  377.   Serial.print(" ");
  378.     dtostrf(s1,1,3,buf2);
  379.   Serial.print(buf2);
  380.   Serial.print(" Waist Radius");
  381. // = /pi/2;
  382.     dtostrf(WaistRadius,3,3,buf2);
  383.   Serial.print(buf2);
  384.   Serial.print(" waist ");
  385.     dtostrf(Waist,1,3,buf2);
  386.   Serial.println(buf2);
  387.   Serial.print(" Folded Fabric + Seam Allowance 1  : ");
  388.     dtostrf(Folded,3,3,buf2);
  389.   Serial.println(buf2);
  390.  
  391.   Serial.print("d90 + Drop + s1 :");
  392.     dtostrf((d90+Drop+s1),3,3,buf2);
  393.   Serial.print(buf2);
  394.   Serial.print(" L ");
  395.   Serial.println(((d90+Drop+s1)>Folded) ? "Bigger" : "Fits") ;
  396.  
  397.   Serial.print("d60 + Drop + s1 :");
  398.     dtostrf((d60+Drop+s1)*.866,3,3,buf2);
  399.   Serial.print(buf2);
  400.   Serial.print(" L ");
  401.   Serial.println(((d60+Drop+s1)*.866>Folded) ? "Bigger" : "Fits") ;
  402.  
  403.   Serial.print("d45 + Drop + s1 :");
  404.     dtostrf((d45+Drop+s1)*.7071,3,3,buf2);
  405.   Serial.print(buf2);
  406.   Serial.print(" L ");
  407.   Serial.println(((d45+Drop+s1)*.7071>Folded) ? "Bigger" : "Fits") ;
  408.  
  409.   Serial.print("d30 + Drop + s1 :");
  410.     dtostrf((d30+Drop+s1)*.5,3,3,buf2);
  411.   Serial.print(buf2);
  412.   Serial.print(" L ");
  413.   Serial.println(((d30+Drop+s1)*.5>Folded) ? "Bigger" : "Fits") ;
  414.   lcd.setCursor(0,0);
  415.   lcd.print("Folded ");
  416.   dtostrf(Folded,3,2,buf2);
  417.   lcd.print(buf2);
  418.   lcd.print("      ");
  419.  
  420.  
  421.  
  422.  
  423.   if((d90+Drop+s1)<Folded) {
  424.     lcd.clear();
  425.     sa=sa90;
  426.     Serial.println("in 90");
  427.     lcd.setCursor(0,0);
  428.     lcd.setCursor(13,0);
  429.     lcd.print("P2n");
  430.     lcd.setCursor(0,1);
  431.     lcd.print("90 w:");
  432.     dtostrf(d90-s1,3,1,buf2);
  433.     lcd.print(buf2);
  434.     lcd.setCursor(8,1);
  435.     lcd.print(" h:");
  436.     dtostrf(d90+Drop+s1,3,1,buf2);
  437.     lcd.print(buf2);
  438.    
  439.     // fits at 90 degrees
  440.   } else if(d60+Drop+s1*.866<Folded) {
  441.     Serial.println("in 60");
  442.     // fits at 60 degrees
  443.     sa=sa60;
  444.     lcd.setCursor(13,0);
  445.     lcd.print("C3n");
  446.     lcd.setCursor(0,1);
  447.     lcd.print("60 w:");
  448.     dtostrf(d60-s1,3,1,buf2);
  449.     lcd.print(buf2);
  450.     lcd.setCursor(8,1);
  451.     lcd.print(" h:");
  452.     dtostrf(d60+Drop+s1,3,1,buf2);
  453.     lcd.print(buf2);
  454.   } else if((d45+Drop+s1)*0.7071<Folded) {
  455.     // fits at 45 degrees
  456.     sa=sa45;
  457.     Serial.println("in 45");
  458.     lcd.setCursor(13,0);
  459.     lcd.print("C4n");
  460.     lcd.setCursor(0,1);
  461.     lcd.print("45 w:");
  462.     dtostrf(d45-s1,2,1,buf2);
  463.     lcd.print(buf2);
  464.     lcd.setCursor(8,1);
  465.     lcd.print("h:");
  466.     dtostrf(d45+Drop+s1,3,1,buf2);
  467.     lcd.print(buf2);
  468.   } else if((d30+Drop+s1)*.5<Folded) {
  469.     sa=sa30;
  470.     // fits at 30 degrees
  471.     Serial.println("in 30");
  472.     lcd.setCursor(13,0);
  473.     lcd.print("C6n");
  474.     lcd.setCursor(0,1);
  475.     lcd.print("30 w:");
  476.     dtostrf(d30-s1,3,1,buf2);
  477.     lcd.print(buf2);
  478.     lcd.setCursor(8,1);
  479.     lcd.print("h:");
  480.     dtostrf(d30+Drop+s1,3,1,buf2);
  481.     lcd.print(buf2);
  482.   }
  483. }
  484.  // delay(3000);
  485.   Serial.print(counter1);
  486.   Serial.println("COUNTER1 ========================  End Loop");
  487.   lcd.setCursor(15,1);
  488. lcd.write(byte(h));
  489.  
  490. if(counter1++ > (counter2*2)) counter1=0;
  491.  
  492. SetBackLight();
  493. delay(25);
  494.  
  495.  
  496.  
  497. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement