Hi Everyone I've made 2 videos that you may (or may not) be interested in. You-know-who has deleted my previous comments because of the links. My first video is called 'My (personal) video to remind me how I did Paul McW's Pico W Lesson 80.' and it shows how you can deinitialise timers without having to use any global variables. My second video is called 'My video for Paul McWhorter's Pico W Lesson 81a - Binary counter using a variable number of LEDS'. I realised that perhaps people might find this useful after I watched Arnold setting up 8 timers one-by-one.
Here is the video for my solution to lesson 81: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-XZHiKpcdHjI.htmlsi=v7XBRRYhHT6J8jP4 It shows that you can pass parameters to a callback.
I believe there is a problem with the synchronization of the One_Shot timers. In my code I created two periodic callbacks each containing one-shot timers with a full second difference(green and red).They should be visibly out of synchronization right away. But that is not so. But predictably by 25-28 seconds, the apparent non-synchronization crashes the program. I have investigated Ms Swift's approach but that has been ineffective in my hands as well. This is the program I am running: import time from machine import Pin,Timer rPin=17 gPin=16 bPin=13 rLed=Pin(rPin,Pin.OUT) gLed=Pin(gPin,Pin.OUT) bLed=Pin(bPin,Pin.OUT) def Function(source): print('Hi') def greenOff(source): gLed.value(0) print('Green Off') def blueBlinker(source): bLed.toggle() def redOff(source): rLed.value(0) print('Red Off') def redBlinker(source): rLed.value(1) print('Red On') red_off_timer=Timer(period=100,mode=Timer.ONE_SHOT,callback=redOff) def redOff(source): rLed.value(0) print('Red Off') def greenBlinker(source): gLed.value(1) green_off_timer=Timer(period=1000,mode=Timer.ONE_SHOT,callback=greenOff) x=0 blueTimer=Timer(period= 2000,mode=Timer.PERIODIC,callback=blueBlinker) redTimer=Timer(period=2000,mode=Timer.PERIODIC,callback=redBlinker) greenTimer=Timer(period=2000,mode=Timer.PERIODIC,callback=greenBlinker) try: while True: print(x) time.sleep(1) if x%5==0: blue_one_shot=Timer(period=4000,callback=Function) x+=1 except KeyboardInterrupt: print('all done') # red_off_timer.deinit() redTimer.deinit() # buzzerTimer.deinit() greenTimer.deinit() blueTimer.deinit() rLed.value(0) gLed.value(0) bLed.value(0) Any suggestions on remedying this desynchronization ( as I surmise it to be)?
So I got it to work with pause. The reason yours didn't work is time.sleep is in seconds, not milliseconds. So my code of led.on, time.sleep(.1), led.off worked. But you are correct it isnt the right way to do it. I thought this homework was too simple! lol
Here is my solution to lesson 81's binary counter homework: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-rmS631rEKIY.html Anyone know why I have to post comments twice for them to take?