from machine import Pin, PWM, ADC, time_pulse_us
import time, cmath
# 继电器控制LED
relayPin = Pin(14, Pin.OUT)
# for i in range(10):
# relayPin.value(1)
# time.sleep(0.5)
# relayPin.value(0)
# time.sleep(0.5)
# Button控制
buttonPin = Pin(23, Pin.IN, Pin.PULL_UP)
# while True:
# time.sleep(1)
# print('Got', buttonPin.value())
# Slide Switch控制
# switchPin = Pin(27, Pin.IN, Pin.PULL_UP)
# while True:
# time.sleep(1)
# print('Got', switchPin.value())
# relayPin.value(switchPin.value())
# 控制舵机
# def map(value, fromlow, fromhigh, tolow, tohigh):
# return int((value-fromlow)*(tohigh-tolow)/(fromhigh-fromlow) + tolow)
# def servo_init(pin):
# pin.freq(50)
# pin.duty(map(0,0,180,25,128))
# def servo(pin, angle):
# pin.duty(map(angle,0,180,25,128))
# pwm = PWM(Pin(23), freq=1000)
# servo_init(pwm)
# while True:
# for i in range(0,181,10):
# servo(pwm, i)
# time.sleep(0.5)
# for i in range(180,-1,-10):
# servo(pwm, i)
# time.sleep(0.5)
# 光敏传感
# dPin = ADC(Pin(35))
# aPin = ADC(Pin(34))
# while True:
# time.sleep(1)
# print(dPin.read(), aPin.read())
# 超声波距离探测
# echoPin = Pin(34, Pin.IN)
# trigPin = Pin(22, Pin.OUT)
# def readDistanceCM():
# trigPin.value(0)
# time.sleep(0.002)
# trigPin.value(1)
# time.sleep(0.01)
# trigPin.value(0)
# duration = time_pulse_us(echoPin, 1)
# return duration * 0.034 / 2
# while True:
# time.sleep(0.5)
# distance = readDistanceCM()
# print(distance)
# 温度传感
# BETA = 3950
# dataPin = ADC(Pin(34))
# dataPin.atten(ADC.ATTN_11DB)
# while True:
# pot_value = dataPin.read() / 4
# celsius = 1 / (cmath.log(1 / (1023. / pot_value - 1)) / BETA + 1.0 / 298.15) - 273.15
# print(pot_value, 'Temp:', celsius)
# time.sleep(0.2)
# WIFI
# import network
# import time
# print("Connecting to WiFi", end="")
# sta_if = network.WLAN(network.STA_IF)
# sta_if.active(True)
# sta_if.connect('Wokwi-GUEST', '')
# while not sta_if.isconnected():
# print(".", end="")
# time.sleep(0.1)
# print(" Connected!")
# Ethernet
# connect/ show IP config a specific network interface
# see below for examples of specific drivers
import network
nic = network.LAN(0)
print(nic.ifconfig())