400 PR 200mm Wheel working 2017

Contributor
Submitted by techrev on Mon, 03/06/2017 - 10:45
Forums

//on china arduino

#include <Wire.h>  // Comes with Arduino IDE
#include <Encoder.h>
#include <LiquidCrystal_I2C.h>
#include "IRremote.h"
Encoder myEnc(2, 3);
int receiver = 11;
long relaypoint;
//long newPosition;
int ic2 = 1;
//int l[5];
int l[6];
IRrecv irrecv(receiver);
decode_results results;  
float lngth=0.0;
float rotn=0.0;
int pulse=0;
int qnty=0;
int pr = 200;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
//0x27
//0x3F
void setup()   /*----( SETUP: RUNS ONCE )----*/{
  lcd.clear();
pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
   pinMode(8, OUTPUT);
     pinMode(9, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn();  
  lcd.begin(16,2);
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Auto Cut");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print("please wait...");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("Enter The Length");
  delay(1000);
 // ABC(4);
  ABC(6);
   
// lngth =l[1]*1000 + l[2]*100 + l[3]*10 + l[4]*1;
 lngth =l[1]*10000 + l[2]*1000 + l[3]*100 + l[4]*10 + l[5]*1;
  l[1]=0;
        l[2]=0;
            l[3]=0;
                l[4]=0;
                    l[5]=0;
  int lgth;
  lgth = lngth;                  
  lngth=lngth-20;
 // lngth=lngth-(lngth/2);

    if (lgth>=5000&&lngth<6000)
  {
    lngth=lngth-11;
    }

 /*  else if (lngth>=6000&&lngth<7000)
  {
    lngth=lngth+47;
    }
    
 else if (lngth>=7000&&lngth<8000)
  {
    lngth=lngth+52;
    }

 else if (lngth>=8000&&lngth<9000)
  {
    lngth=lngth+17;
    }
    
 else if (lngth>=9000&&lngth<10000)
  {
    lngth=lngth+74;
    }
    */
 rotn=lngth/200;//2pr is
 pulse=rotn*80;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("The length is");
  lcd.setCursor(0,1);  
lcd.print(lgth);
  delay(2000);
 Serial.println(lngth);
delay(1000);
lcd.clear();
ic2 = 1;
lcd.setCursor(0,1);
lcd.print("Enter The Qnty");
  delay(100);
   ABC(3);
   qnty =l[1]*10+l[2]*1;
   l[1]=0;
        l[2]=0;
            l[3]=0;
                l[4]=0;
                    l[5]=0;
   lcd.clear();
  // lcd.setCursor(0,0);
   //lcd.print(qnty);
   //Serial.println(qnty);
//delay(1000);
// lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("The Qnty is");
lcd.setCursor(0,1);  
lcd.print(qnty);
Serial.println(qnty);
delay(2000);
 lcd.clear();
  lcd.setCursor(0,0);
 
  lcd.print("Rolling START...");
  delay(500);
digitalWrite(6,HIGH);
// roller start
// delay(300);
// digitalWrite(6,LOW);
// digitalWrite(8,HIGH);
//digitalWrite(7,LOW);
}
long oldPosition=0;
int counter=0;
void loop()
{
  while(counter<qnty)
  {
   long newPosition = myEnc.read()/20;// 38 for 100 pulse per rotation or 360 degree  
   while (newPosition > oldPosition)  
      {
       newPosition = myEnc.read()/20;//
       oldPosition = newPosition;
       relaypoint = newPosition;
       digitalWrite(6,LOW);
    
         if (relaypoint%pulse == 0)
           {
            counter=counter+1;
            digitalWrite(7,HIGH); //roller stop
            delay(2000);
            digitalWrite(7,LOW);
            delay(2000);
            digitalWrite(8,HIGH);// cutter up
            delay(3000);
            digitalWrite(8,LOW);//
            delay(2000);
            digitalWrite(9,HIGH);// cutter down
            delay(3000);
            digitalWrite(9,LOW);//
            delay(1000);
            myEnc.write(0);
             lcd.setCursor(0,0);
             lcd.print("                               ");
             lcd.setCursor(0,0);
             lcd.print(counter);
            newPosition=0;
            oldPosition=0;
            digitalWrite(6,HIGH); // roller start
            delay(500);
            digitalWrite(6,LOW);
           }
         }

     
      
      }
     lcd.setCursor(0,1);
     lcd.print("Completed");
     digitalWrite(7,HIGH); //roller stop
     delay(100);
     digitalWrite(7,LOW);
     delay(4000);
     exit(0);
     
}

 

 

 

void ABC(int q)
{
     do{
 if (irrecv.decode(&results)) // have we received an IR signal?
  {
   
    translateIR();
     ic2=ic2+1;
    irrecv.resume(); // receive the next value
  }
  } while(ic2<q);
}

  void translateIR() // takes action based on IR code received
{
    switch(results.value)
  {

  case 0xFF6897:  //0
  l[ic2] = 0;
   
    lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
     break;

/*  case 0xFF9867:  //-
    Serial.println(" delete           ");
    break;

  case 0xFFB04F:  //c
    Serial.println(" Cancel           ");
    break;*/

  case 0xFF30CF:  //1
   l[ic2] = 1;
  //  Serial.println(l[ic2]);
    lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
        break;

  case 0xFF18E7:  //2
   l[ic2] = 2;
  //  Serial.println(l[ic2]);
     lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
    break;

  case 0xFF7A85:  //3
  l[ic2] = 3;
   // Serial.println(l[ic2]);
      lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
    break;

  case 0xFF10EF: //4
   l[ic2] = 4;
  // Serial.println(l[ic2]);
   lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
     break;

  case 0xFF38C7:  //5
     l[ic2] = 5;
  // Serial.println(l[ic2]);
     lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
     break;

  case 0xFF5AA5:  //6
     l[ic2] = 6;
   // Serial.println(l[ic2]);
    lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
    break;

  case 0xFF42BD:  //7
   l[ic2] = 7;
   // Serial.println(l[ic2]);
    lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
    break;

  case 0xFF4AB5:  //8
    l[ic2] = 8;
    //Serial.println(l[ic2]);
    lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
    break;

  case 0xFF52AD:  //9
    l[ic2] = 9;
    //Serial.println(l[ic2]);
    lcd.setCursor(ic2,0);
    lcd.print(l[ic2]);
    break;
/*
  case 0xFFA25D:  //exit
   // lcd.setCursor(0,0);
   // lcd.print(" START ");
   //Relaypt();
    break;

  case 0xFF629D:  
    Serial.println(" CH             ");
    break;

  case 0xFFE21D:  //menu
    Serial.println(" Menu            ");
    break;

  case 0xFF22DD:  //test
    Serial.println(" TEST           ");
    break;

  case 0xFF02FD:  //+
    Serial.println(" NEXT           ");
    break;*/

 /* case 0xFFC23D:  //undo
    Serial.println(" undo     ");
    delay(1000);
    exit(0);
    break;*/
/*
  case 0xFFE01F:  //back
    Serial.println(" VOL-           ");
    break;

  case 0xFFA857:  //play
    Serial.println(" play           ");
    break;

  case 0xFF906F:  //forward
    Serial.println(" EQ             ");
    break;*/
    
  default:
    Serial.println(" other button   ");

  }
  delay(500);
}

 
\