MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / blink

Function blink

blink.py:13–112  ·  view source on GitHub ↗
(ledPin=None)

Source from the content-addressed store, hash-verified

11 from digitalio import DigitalInOut, Direction
12
13def blink(ledPin=None):
14 cmnd = ""
15 minus = False
16
17 if ledPin == None or ledPin == "":
18 ledPin = Pydos_hw.led
19 elif sys.implementation.name.upper() == 'CIRCUITPYTHON':
20 ledPin = getattr(board,str(ledPin).upper().replace("'","").replace('"',''))
21 else:
22 if type(ledPin) == str:
23 if ledPin[:1] == '-':
24 minus = True
25 try:
26 ledPin = int(ledPin)
27 except:
28 if type(ledPin) == str:
29 ledPin = ledPin.upper()
30
31
32 # Micropython: pass a negative pin value if the led turns off with a value of 1
33 if (type(ledPin) == int and ledPin < 0) or minus:
34 ledPin = abs(ledPin)
35 ledOff = True
36 else:
37 ledOff = False
38
39 if sys.implementation.name.upper() == 'MICROPYTHON':
40
41 # nano connect is special case becuase LED uses the SPI SCK pin
42 if sys.implementation._machine in ['Arduino Nano RP2040 Connect with RP2040','Teensy 4.1 with MIMXRT1062DVJ6A']:
43 # ledPin = [6,13][(['Arduino Nano RP2040 Connect with RP2040','Teensy 4.1 with MIMXRT1062DVJ6A'].index(sys.implementation._machine))]
44
45 for i in range(len(Pydos_hw.SDdrive)):
46 if Pydos_hw.SCK[i] == ledPin:
47 if Pydos_hw.SDdrive[i] != None:
48 from os import umount
49 print("Unmounting SD card ("+Pydos_hw.SDdrive[i]+") because of shared SCK pin")
50 umount(Pydos_hw.SDdrive[i]) # Nano Connect uses LED pin for SPI SCK
51 Pydos_hw.SDdrive[i] = None
52 # If anything has used the SPI interface need to free up SCK
53 Pydos_hw.SPI_deinit(i)
54 break
55
56 if ledPin != None:
57 led = Pin(ledPin, Pin.OUT)
58 else:
59 raise ValueError("LED pin not defined in pydos_bcfg.py!")
60
61 elif sys.implementation.name.upper() == 'CIRCUITPYTHON':
62
63 # nano connect/Tennsy 4.1 are special cases becuase LED uses the SPI SCK pin
64 if board.board_id in ["arduino_nano_rp2040_connect","teensy41"]:
65
66 for i in range(len(Pydos_hw.SDdrive)):
67 if Pydos_hw.SCK[i] == ledPin:
68 if Pydos_hw.SDdrive[i] != None:
69 from storage import umount
70 print("Unmounting SD card ("+Pydos_hw.SDdrive[i]+") because of shared SCK pin")

Callers 1

blink.pyFile · 0.85

Calls 6

valueMethod · 0.95
DigitalInOutClass · 0.85
SPI_deinitMethod · 0.80
deinitMethod · 0.80
read_keyboardMethod · 0.45

Tested by

no test coverage detected