User Manual

87
if((Last_RoB_Status == 0)&&(Current_RoB_Status == 1)){ // If DT value converts
from low to high, the globalCounter adds 1.
}
if((Last_RoB_Status == 1)&&(Current_RoB_Status == 0)){ //If DT value converts
from high to low,
globalCounter --; // the globalCounter
decreases 1.
}
}
printf("globalCounter : %d\n",globalCounter); // Print the value of globaCounter.
void btnISR(void): // If the rotary encoder is pressed down, reset the value.
For Python users:
Step 2: Get into the folder of the code.
cd /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/Python
Step 3: Run
sudo python 12_rotaryEncoder.py
Code Explanation
globalCounter = 0 # Set a global variable to count
flag = 0 # Set a flag for reverse spinning.
Last_RoB_Status = 0 # Set a variable to store the previous state of pinB
Current_RoB_Status = 0 # Set a variable to store the present state of pinB
# Define a function to deal with rotary encoder
def rotaryDeal():
global counter
global Last_RoB_Status, Current_RoB_Status
flag = 0
Last_RoB_Status = GPIO.input(RoBPin) # Store channel B state
# When RoAPin level changes
while(not GPIO.input(RoAPin)): # When channel A is not in low, exit the while
loop
Current_RoB_Status = GPIO.input(RoBPin)
flag = 1
if flag == 1: # If flag value is 1, the rotary encoder is CW rotating
# Reset flag
flag = 0
SunFounder