Browse Source

Add pinouts and refactor some code

master
Elis Axelsson 5 years ago
parent
commit
af02a907d0
  1. 1
      Makefile
  2. 14
      code/main.py
  3. 16
      code/pinouts.py

1
Makefile

@ -1,4 +1,5 @@
copy:
ampy --port /dev/ttyUSB0 put code/boot.py
ampy --port /dev/ttyUSB0 put code/main.py
ampy --port /dev/ttyUSB0 put code/pinouts.py
ampy --port /dev/ttyUSB0 put code/hcsr04.py

14
code/main.py

@ -1,19 +1,19 @@
def blink():
import machine, time
from pinouts import NodeMCU as pins
from hcsr04 import HCSR04
import time
import machine
print("blink")
def blink():
pin = machine.Pin(2, machine.Pin.OUT)
while True:
pin.value(not pin.value())
time.sleep_ms(500)
def distance(trigger, echo):
from hcsr04 import HCSR04
import time
sensor = HCSR04(trigger_pin=trigger, echo_pin=echo)
def distance():
sensor = HCSR04(trigger_pin=pins.D0, echo_pin=pins.D3)
while True:
print(sensor.distance_cm())

16
code/pinouts.py

@ -0,0 +1,16 @@
class NodeMCU:
"""
Pinout mapping of the NODEMCU Board I've got.
"""
D0 = 16
D1 = 5
D2 = 4
D3 = 0
D4 = 2
D5 = 14
D6 = 12
D7 = 13
D8 = 15
D9 = 3
D10 = 1
Loading…
Cancel
Save