Whats the best way or does anyone have a sample of code / pinout to put a simple switch (momentary or latching) to turn the leds on and off? I have done it through the python interpreter as in the docs, but I want to hardwire something to toggle that while my other code is running.
Are you referring to the LEDs that light the button on Vizy?
No, I meant the IR leds on the outdoor enclosure. Sorry for not putting that in the body and just mentioning that in the subject. What I am hoping to have is the ability to have a switch mounted on the back of the OE so I can just flip it or press it to engage the IR’s and have the software monitoring the gpio pins to turn it on / off.
You can use the outdoor enclosure switch as a simple momentary switch hooked up to one of the I/O bits, but it’s probably easier to use button() and button_pressed() to determine if the outdoor enclosure button has been pressed, assuming you’ve wired it up according to this guide.
You can then use vcc12() to turn the LEDs off and on, based on what you read from button() and/or button_pressed().
Thank you, that got me going. Its a bit temperamental because of the frame rate, but if you tap the button quickly and don’t hold, it will toggle the lights. I used the pet companion as my base app to monitor a video feed and take a frame to do some processing. I am new to Python, so this code may be garbage - please forgive me.
def loop(self): while self.run_loop: if self.pb.button() and self.switchNotPressed: self.switchNotPressed = False if self.lightOff: self.pb.vcc12(True) self.lightOff = False else: self.pb.vcc12(False) self.lightOff = True else: self.switchNotPressed = True
Edit: I have tried with the switchNotPressed and without - I didn’t see any significant change, but I was trying to buy a frames worth of time on the press.
Nice work Your code might benefit from a small delay inside the while loop –
import time time.sleep(0.050) # sleep 50ms
Otherwise the loop will tend to grab lots of CPU and loop faster than you probably want.
Thank you for the suggestion. My loop has synchronous processing inside that is somewhat intensive, so it slows it down a bit, otherwise, I will definitely add a delay.