Step 7Using a rotary encoder
A rotary encoder on A and B channel (both a pin) with one common pin that can be either connected to GND or Vcc. As we use it with interrupts, we'll connect it to GND. The A and B channel open and close in a fixed patern and by reading this pattern, we know in what way the encoder is turning. By adding one channel to and interrupt, we are able to trigger the read subroutine automatically when the encoder is turned.
In bascom, that will give us:
A Alias Pind.3
B Alias Pind.4
Config A = Input
Config B = Input
Config Int0 = Falling
Dim Counter As Integer
Set B
On Int0 Getencoder
Counter = 0
Enable Interrupts
Enable Int0
Do
Your code here
Loop
Getencoder:
Waitms 1
If A = 0 Then
If B = 0 Then Incr Counter Else Decr Counter
End If
Return
End
The pushbutton on the rotary encoder works just like a normal button, so nothing much to explain there.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|

















































