Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino code for OMRON Encoder
#1
#include <Encoder.h>

int panel_length = 500;
int quantity = 5;
int i = 0;
int red = 7;
long relaypoint;
Encoder myEnc(2, 3);
void setup() {
  Serial.begin(9600);
// Serial.println("Basic Encoder Test:");
  pinMode(red, OUTPUT);
}

long oldPosition  =0;

void loop() {
  digitalWrite(red,LOW);
  long newPosition = myEnc.read()/1000; // use 1000, to get 1 pulse per 1 rev or 100, 10, even 1 to get fine adjustments
 
while (newPosition > oldPosition)  {
    oldPosition = newPosition;
    relaypoint = oldPosition;
    Serial.println(relaypoint);
   
        if (relaypoint % panel_length == 0)
    {
    Serial.println("Rolling Motor Stop");
    Serial.println("Cutter START, RED LED light ON");
    digitalWrite(red,HIGH);
    //delay(3000);
    //digitalWrite(red,LOW);
    Serial.println("Cutter STOP, RED LED light OFF");
    Serial.println("Rolling Motor START");     
    Serial.println("Quantity :");
    Serial.println(i);
    i = i+1;
    if (i >= quantity){
    Serial.println("Competed for given quanity");
    }
}
   
}
}
Reply
#1
#include <Encoder.h>

int panel_length = 500;
int quantity = 5;
int i = 0;
int red = 7;
long relaypoint;
Encoder myEnc(2, 3);
void setup() {
  Serial.begin(9600);
// Serial.println("Basic Encoder Test:");
  pinMode(red, OUTPUT);
}

long oldPosition  =0;

void loop() {
  digitalWrite(red,LOW);
  long newPosition = myEnc.read()/1000; // use 1000, to get 1 pulse per 1 rev or 100, 10, even 1 to get fine adjustments
 
while (newPosition > oldPosition)  {
    oldPosition = newPosition;
    relaypoint = oldPosition;
    Serial.println(relaypoint);
   
        if (relaypoint % panel_length == 0)
    {
    Serial.println("Rolling Motor Stop");
    Serial.println("Cutter START, RED LED light ON");
    digitalWrite(red,HIGH);
    //delay(3000);
    //digitalWrite(red,LOW);
    Serial.println("Cutter STOP, RED LED light OFF");
    Serial.println("Rolling Motor START");     
    Serial.println("Quantity :");
    Serial.println(i);
    i = i+1;
    if (i >= quantity){
    Serial.println("Competed for given quanity");
    }
}
   
}
}
Reply
CAA


Forum Jump:


Users browsing this thread: 1 Guest(s)