Finding Time elapsed in doing work using MicroPython

      Program for finding the time elapsed  using Micropython 

Here in this blog i am gonna going to write a program for finding the time elapsed in doing work by using micropython and NodeMcu as controller. Basically in this session we will use both RTC class 
and Utime module for finding the localtime and also time elapsed.
 Through RTC class we will define the time in tuple form, then we will use the Utime module for finding the time difference.
Here i have written a short program for finding time for the Led is on in the NodeMcu 
________________________________________________________________________________

                                                            Program

import machine
import time 
import utime
rtc = machine.RTC()
rtc.datetime((2017, 8, 23, 11,54, 10,10,10 ))
stop= ([0])
start=([0])
a=0
led = machine.Pin(16, machine.Pin.OUT)
print(rtc.datetime())
#rtc.info()
while True:
   
    
    n = input('enter 1 no')
    if (n == '2'):
        
        led.on()
        #utime.localtime()
        start= utime.ticks_ms()
       # utime.time()
        
        print( utime.localtime())
        
    elif (n == '1'):
        led.off()
        stop= utime.ticks_ms()
        print (utime.localtime())
        a= utime.ticks_diff(stop,start)
        sec= a/1000
        print (sec)
        stop= ([0])
        start=([0])
        
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                                               Program Ends    

Hope this program will help you in making Real time Clocks and Stopwatch. For more tips and guide for using NodeMcu with micropython , Read my all blogs.
     
    

Comments

Popular posts from this blog

Connecting NodeMcu to a network using Micro Python