Skip to content

Commit 5c8cabf

Browse files
committed
Ard programs
0 parents  commit 5c8cabf

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

ard_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#this is used to check the running voltage of arduino.
2+
try:
3+
from pyfirmata import Arduino, util
4+
except:
5+
import pip
6+
pip.main(['install','pyfirmata'])
7+
from pyfirmata import Arduino, util
8+
9+
import time
10+
board = Arduino("COM4")
11+
it = util.Iterator(board)
12+
it.start()
13+
Tv1 = board.get_pin('a:0:i')#'a'nalog/'d'igital:pin number:'i'nput/'o'utput/'p'wm
14+
time.sleep(1)
15+
print(Tv1.read())

blinkled.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pyfirmata import Arduino, util
2+
import time
3+
4+
board = Arduino("COM4")
5+
it = util.Iterator(board)
6+
it.start()
7+
print("Hello!Arduino")
8+
LED = board.get_pin("d:13:o")
9+
10+
while True:
11+
LED.write(1)
12+
time.sleep(0.5)
13+
LED.write(0)
14+
time.sleep(0.5)
15+
16+
board.exit()

led_pwm_controlled.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pyfirmata import Arduino,util
2+
import time
3+
4+
board = Arduino("COM4")
5+
it = util.Iterator(board)
6+
it.start()
7+
8+
led = board.get_pin("d:9:o")
9+
10+
# for a in range(0,255):
11+
# led.write()
12+
# time.sleep(0.8)
13+
14+
# for a in range(255,0):
15+
while True:
16+
a = 0
17+
while a<=255:
18+
led.write(a)
19+
time.sleep(0.008)
20+
a+=1
21+
while a>=0:
22+
led.write(a)
23+
time.sleep(0.008)
24+
a-=1
25+
time.sleep(0.8)
26+
board.exit()
27+
28+
29+

switch_led.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pyfirmata import Arduino, util
2+
import time
3+
4+
board = Arduino("COM4")
5+
it = util.Iterator(board)
6+
it.start()
7+
8+
sw = board.get_pin("d:3:i")
9+
led = board.get_pin("d:13:o")
10+
11+
while True:
12+
value = sw.read()
13+
if value == 1:
14+
led.write(1)
15+
else:
16+
led.write(0)
17+
board.exit()
18+

0 commit comments

Comments
 (0)