NodeMCU Projects: Difference between revisions

 
(5 intermediate revisions by the same user not shown)
Line 6:
= Small Projects =
 
== PlayingLED with GPIOON/OFF ==
 
<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">
fromimport machine import Pin, SPI
import max7219, utime
import urequests as requests
import time
 
# Deep Sleep
#def deep_sleep(delta):
# rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
# if machine.reset_cause() == machine.DEEPSLEEP_RESET:
# print('woke from a deep sleep')
# rtc.alarm(rtc.ALARM0, delta*1000*60)
# machine.deepsleep()
# LCD Config
spi = machine.SPI(1, 10000000)
d = max7219.Max7219(32, 8, spi, machine.Pin(15), False)
 
cntry = ["India", "ChinaCanada", "ItalyIreland", "IranUSA", "CanadaGermany", "USAItaly", "IrelandFrance", "GermanySpain", "Pakistan", "France", "SpainKorea"]
 
 
while True:
# Flash all LEDs
# Print Global Data
for i in cntryrange(3):
d.fill(1)
d.show()
time.sleep(50.2)
d.fill(0)
d.show()
time.sleep(0.2)
 
 
# Print Global Data
try:
res = link requests.get(url= 'http://coronavirus-19-api.herokuapp.com/countries/%sall' %i)
if res.status_code == 200:
flash_led(1,0.1,0.1)
else:
flash_led(2,0.5,0.1)
data = res.json()
print("Global: " + str(data["cases"]))
d.marquee("Global: " + str(data["cases"]))
except OSError:
print(i, "Global: Error")
d.marquee(i + "Global: Error")
time.sleep(5)
 
 
# Print Country Data
for i in cntry:
link = 'http://coronavirus-19-api.herokuapp.com/countries/%s' %i
try:
res = requests.get(url='http://coronavirus-19-api.herokuapp.com/all'link)
if res.status_code == 200:
flash_led(1,0.1,0.1)
tryelse:
flash_led(2,0.5,0.1)
data = res.json()
print("All - Cases: " + str(data["casescountry"]) + " Recovered: " + str(data["recoveredcases"]) + " DeathsToday: " + str(data["deathstodayCases"]))
d.marquee("All - Cases: " + str(data["casescountry"]) + " Recovered: " + str(data["recoveredcases"]) + " DeathsToday: " + str(data["deathstodayCases"]))
except OSError:
print(i, ": Error")
Line 580 ⟶ 617:
time.sleep(5)
continue
 
# Print Country Data
 
for i in cntry:
# Sleep for 30 minutes
link = 'http://coronavirus-19-api.herokuapp.com/countries/%s' %i
sleep = 5
try:
d.marquee("Sleep " + str(sleep) + " min")
res = requests.get(url=link)
flash_led(5,0.1,0.1)
data = res.json()
#def deep_sleep(deltasleep):
print(str(data["country"]) + " - Cases: " + str(data["cases"]) + " Recovered: " + str(data["recovered"]) + " Critical: " + str(data["critical"]) + " Deaths: " + str(data["deaths"]) + " TodayCases: " + str(data["todayCases"]) + " TodayDeaths: " + str(data["todayDeaths"]))
d.marquee(str(data["country"]) + " - Cases: " + str(data["cases"]) + " Recovered: " + str(data["recovered"]) + " Critical: " + str(data["critical"]) + " Deaths: " + str(data["deaths"]) + " TodayCases: " + str(data["todayCases"]) + " TodayDeaths: " + str(data["todayDeaths"]))
except OSError:
print(i, ": Error")
d.marquee(i + ": Error")
time.sleep(5)
continue
# Sleep for 30 minutes
print("Deepsleep for 30 minutes")
deep_sleep(30)
</syntaxhighlight>
 
= TM1637 CLock =
 
Download Library:
https://github.com/mcauser/micropython-tm1637/blob/master/tm1637.py
 
{{UC}}