NodeMCU Projects: Difference between revisions
→LED ON/OFF
(5 intermediate revisions by the same user not shown) | |||
Line 6:
= Small Projects =
==
<syntaxhighlight lang="python">
from machine import Pin
led = Pin(2, Pin.OUT)
led.value()
led.value(1)
led.value(0)
</syntaxhighlight>
== Toggle GPIO ==
<syntaxhighlight lang="python">
Line 549 ⟶ 561:
<syntaxhighlight lang="python">
import max7219, utime
import urequests as requests
import time
#def deep_sleep(delta):▼
# LCD Config
spi = machine.SPI(1, 10000000)
d = max7219.Max7219(32, 8, spi, machine.Pin(15), False)
cntry = ["India", "
# Flash all LEDs
# Print Global Data▼
d.fill(1)
d.show()
d.fill(0)
d.show()
time.sleep(0.2)
try:
if res.status_code == 200:
flash_led(1,0.1,0.1)
▲ else:
flash_led(2,0.5,0.1)
print("Global: " + str(data["cases"]))
d.marquee("Global: " + str(data["cases"]))
time.sleep(5)
for i in cntry:
link = 'http://coronavirus-19-api.herokuapp.com/countries/%s' %i
try:
res = requests.get(url=
if res.status_code == 200:
flash_led(1,0.1,0.1)
flash_led(2,0.5,0.1)
data = res.json()
print(
d.marquee(
except OSError:
print(i, ": Error")
Line 580 ⟶ 617:
time.sleep(5)
continue
▲ # Print Country Data
▲ for i in cntry:
▲ link = 'http://coronavirus-19-api.herokuapp.com/countries/%s' %i
sleep = 5
▲ try:
d.marquee("Sleep " + str(sleep) + " min")
flash_led(5,0.1,0.1)
▲ data = res.json()
▲ except OSError:
▲ print(i, ": Error")
▲ d.marquee(i + ": Error")
▲ time.sleep(5)
▲ # Sleep for 30 minutes
</syntaxhighlight>
= TM1637 CLock =
Download Library:
https://github.com/mcauser/micropython-tm1637/blob/master/tm1637.py
{{UC}}
|