Rotary Encoder Kit RE08A: How to count pulse and test code

Digital Fiber, Photoelectric, Laser Range, Optical, Temperature, Rotary Encoder, Ultrasonic, Gas, Gyro, Accelerometer, FlexiBend, Flexiforce, Compass......

Rotary Encoder Kit RE08A: How to count pulse and test code

Postby RothmanAwesome » Fri May 09, 2014 11:58 am

//This is an example on how to count the pulse
from the RE08A


/* Read RE08A Encoder
* Connect GND of RE08A to GND of Arduino
*Connect +5V of RE08A
*Connect Sig of RE08A to Pin 11 of Arduino
*Connect +leg of LED to Pin8
*Connect the -leg of LED to GND of Arduino

* Sketch by Rothman Noh
* v. 0.1 - very basic functions - mw 20061220
*
*/


int ledPin = 8; // choose the pin for the Reference LED
int encoderPin= 11;// Sig from RE08 to pin 11 of Arduino
int val = 0;
int currentState = LOW;
int previousState = LOW;
int counter = 0;
int n = LOW;

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(encoderPin, INPUT); // declare pushbutton as input
Serial.begin (9600);
}

void loop() {
n = digitalRead(encoderPin);
if ((previousState == LOW) && (n == HIGH))
{
if (digitalRead(currentState) == LOW)
{
counter--;
}
else
{
counter++;
}
Serial.print (counter);
Serial.print ("/"); // To open Serial Monitor push ( Ctrl+Shift+M)
}
previousState= n;
digitalWrite(ledPin, n);//LED will detect any change in 'n'
}
RothmanAwesome
Fledgling
 
Posts: 1
Joined: Fri May 09, 2014 11:54 am

Return to Sensor

Who is online

Users browsing this forum: No registered users and 12 guests