Basic Demo; Material Required; Connections; Code - Seeed Grove - Mouse Encoder Quick Start Manual

Hide thumbs Also See for Grove - Mouse Encoder:
Table of Contents

Advertisement

 

Basic demo

This demo shows how to detect position and detect direction.

Material required

Seeeduino V4.2
Base shield V2.0
USB cable (type A to micro type B)

Connections

Connect materials as shown below:

Code

/* Read Quadrature Encoder
1
2
* Connect Encoder to Pins encoder0PinA, encoder0PinB, and +5V.
3
*
4
* Sketch by max wolf / www.meso.net
5
* v. 0.1 - very basic functions - mw 20061220
6
*
7
*/
8
9
10
int
val;
11
int encoder0PinA =
12
int encoder0PinB =
13
int encoder0Pos =
0;
14
int encoder0PinALast =
15
int n =
LOW;
16
17
void setup()
{
18
pinMode
(encoder0PinA,INPUT);
19
pinMode
(encoder0PinB,INPUT);
Serial.begin
(115200);
20
}
21
22
23
void loop()
{
24
n =
digitalRead(encoder0PinA);
25
if
((encoder0PinALast == LOW) && (n == HIGH))
26
if
(digitalRead(encoder0PinB) == LOW)
27
encoder0Pos--;
}
else
{
28
29
encoder0Pos++;
30
}
31
Serial.println(encoder0Pos);
32
Serial.println
("/");
}
33
34
encoder0PinALast =
35
}
 
3;
4;
LOW;
n;
{
{

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Grove - Mouse Encoder and is the answer not in the manual?

Questions and answers

Table of Contents