Skip to content

Commit 1502094

Browse files
committed
made API more Pythonic with alias legacy Arduino methods
1 parent e1198b7 commit 1502094

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

arduino/arduino.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
__author__ = "ubi de feo / murilo polese"
2+
__license__ = "MPL 2.0"
3+
__version__ = "0.1.0"
4+
__maintainer__ = "Arduino"
5+
16
from machine import Pin, ADC, PWM
27
from time import sleep_ms, ticks_us
38
from random import randrange
@@ -36,22 +41,28 @@ def lerp(start, stop, amount):
3641
def pinMode(_pin, _mode):
3742
return Pin(_pin, _mode)
3843

39-
def digitalWrite(_pin, _signal):
44+
def digital_write(_pin, _signal):
4045
p = Pin(_pin, Pin.OUT)
4146
p.value(_signal)
4247

43-
def digitalRead(_pin):
48+
def digitalWrite(_pin, _signal):
49+
return digital_write(_pin, _signal)
50+
51+
def digital_read(_pin):
4452
p = Pin(_pin, Pin.IN)
4553
return p.value()
4654

47-
def delay(_ms):
48-
sleep_ms(_ms)
55+
def digitalRead(_pin):
56+
return digital_read(_pin)
4957

50-
def analogRead(_pin):
58+
def analog_read(_pin):
5159
p = ADC(Pin(_pin))
5260
return p.read_u16()
5361

54-
def analogWrite(_pin, _duty_cycle):
62+
def analogRead(_pin):
63+
return analog_read(_pin)
64+
65+
def analog_write(_pin, _duty_cycle):
5566
p = PWM(Pin(_pin))
5667
p.freq(1000)
5768
duty = mapi(_duty_cycle, 0, 255, 0, 1023)
@@ -60,6 +71,13 @@ def analogWrite(_pin, _duty_cycle):
6071
p.duty(0)
6172
p.deinit()
6273

74+
def analogWrite(_pin, _duty_cycle):
75+
return analog_write(_pin, _duty_cycle)
76+
77+
def delay(_ms):
78+
sleep_ms(_ms)
79+
80+
6381
# the following methods are just for testing
6482
# will produce output when this module is run as __main__
6583
def preload():

0 commit comments

Comments
 (0)