User Manual
86
For C language users:
Step 2: Get into the folder of the code.
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C
Step 3: Compile
make 12_rotaryEncoder
Step 4: Run the executable file above
sudo ./12_rotaryEncoder
Code Explanation
#define RoAPin 0 // CLK connects to B17, define B17 as 0 in wiring Pi.
#define RoBPin 1 // DT connects to GPIO1, define B18 as 1 in wiring Pi.
#define SWPin 2 // SW connects to GPIO2
void rotaryDeal(void) : // Pi detects the pulse when spinning the rotary encoder, and
judge the spinning direction, then increase or decrease the value of globalCounter to
record the angular displacement.
Last_RoB_Status = digitalRead(RoBPin); // Read the value of DT
while(!digitalRead(RoAPin){ // If CLK is low, run the program below.
Current_RoB_Status = digitalRead(RoBPin); // Read the value of DT, and store it
in Current_RoB_Status.
flag = 1;
}
if(flag == 1) // If CLK outputs low level, then flag=1
{flag = 0;
SunFounder