Skip to content

Commit 13349ee

Browse files
committed
rotary_encoder
1 parent 17e33ba commit 13349ee

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
<h1 align = center> Arduino Uno R3 </h1>
1+
<h1 align = center> Arduino UNO R3 </h1>
22

3-
## These programs can used for any arduino UNO
3+
## These programs can used for any Arduino UNO
44

55
### Connect circuit according to the sunfounder arduino
66

77
[Arduino circuit link](https://www.sunfounder.com/learn/category/Super-Kit-V2-0-for-Arduino.html)
88

99
*_Before connecting the circuit verify the pins with code and link_*
1010

11-
![Alternate text](https://img.shields.io/badge/Clones-65%2B-green)
11+
![Alternate text](https://img.shields.io/badge/Clones-75%2B-g)
1212
![Alt text](https://img.shields.io/badge/python-v3.8-yellow)
13+
![Alt text](https://img.shields.io/badge/Arduino-UNO-green)
14+
1315

1416
## PROJECTS
1517

@@ -66,7 +68,7 @@ Control RGB led using arduino
6668

6769
#### flowing_led
6870

69-
Turn on leds one after the other and simultaneously turninng off your previous led
71+
Turn on leds one after the other and simultaneously turning off your previous led
7072

7173
<img src = "https://cdn.instructables.com/FHC/Z5OJ/JDCBL4TD/FHCZ5OJJDCBL4TD.ANIMATED.LARGE.gif" height = 300 width = 350>
7274

@@ -80,10 +82,18 @@ Control multiple LED lights using Tkinter
8082

8183
![Alternate text](https://media1.giphy.com/media/Wqd5qegydUOE4nsq5o/giphy.gif)
8284

83-
(there's a liitle problem in it but the programs still runs andd performs its task if someone finds a solution let me know)
85+
(there's a little problem in it but the programs still runs andd performs its task if someone finds a solution let me know)
8486

8587
#### 7segmentdisplay
8688

8789
Using this display numbers from 1 to 6
8890

91+
![](https://i.pinimg.com/originals/dc/05/9f/dc059fbba8ee906341cf76f4e6529037.gif)
92+
8993
*You can add more numbers and letters according to the pin diagram and apply it for many uses*
94+
95+
#### rotary_encoder
96+
97+
This program tells the angular displacement of the rotary. It converts angular position to analog/digital output signal
98+
99+
![](https://osoyoo.com/wp-content/uploads/2017/09/rotary-encoder.gif)

rotary_encoder.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from pyfirmata import Arduino, util
2+
import time
3+
4+
board = Arduino("COM4")
5+
it = util.Iterator(board)
6+
it.start()
7+
8+
clk = board.get_pin("d:2:i")
9+
dt = board.get_pin("d:3:i")
10+
sw = board.get_pin("d:4:o")
11+
12+
def encoder():
13+
oldA = 1
14+
oldB = 1
15+
result = 0
16+
newA = clk.read()
17+
newB = dt.read()
18+
if newA != oldA or newB != oldB:
19+
if oldA == 1 and newA == 0:
20+
result = oldB*2-1
21+
oldA = newA
22+
oldB = newB
23+
return result
24+
encoderval = 0
25+
change = 0
26+
while True:
27+
sw.write(1)
28+
change = encoder()
29+
encoderval = encoderval + change
30+
if sw.read() == 0:
31+
encoderval = 0
32+
print(encoderval)
33+
#time.sleep(1)

0 commit comments

Comments
 (0)