So i've got this op and running:
Code: Select all
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, 1)Any thoughts?
Regards.
Kim.
Code: Select all
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, 1)Code: Select all
switch on
sleep
switch offCode: Select all
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, 1)
sleep(0.1)
GPIO.output(16,0)
GPIO.cleanup()I think the time on this is ok, but if i want to set up the time, how do i do then?elParaguayo wrote:At the most basicHow long a pulse do you need? How accurate does it need to be?Code: Select all
switch on sleep switch off
I think the pigpio module has a trigger function that may also suit your needs: http://abyz.co.uk/rpi/pigpio/python.html#gpio_trigger
Fantastic, tanks a lot, and thanks for the heads up on the GPIO.cleanup()Laurens-wuyts wrote:you could do something like this:After you used the GPIO pins and your program is done, you need to run "GPIO.cleanup()" so you don't get error messages.Code: Select all
import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BOARD) GPIO.setup(16, GPIO.OUT) GPIO.output(16, 1) sleep(0.1) GPIO.output(16,0) GPIO.cleanup()![]()
Laurens
Hi again, is there a way to do the same code, but instead of starting with a 1 and ending with a 0, start with 0 and end with 1?Laurens-wuyts wrote:you could do something like this:After you used the GPIO pins and your program is done, you need to run "GPIO.cleanup()" so you don't get error messages.Code: Select all
import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BOARD) GPIO.setup(16, GPIO.OUT) GPIO.output(16, 1) sleep(0.1) GPIO.output(16,0) GPIO.cleanup()![]()
Laurens
That's because of the GPIO.cleanup. What that does is to set the GPIOs used by your program back to the default levels and modes.Kimovitzh wrote:Hi again, is there a way to do the same code, but instead of starting with a 1 and ending with a 0, start with 0 and end with 1?
I tried the obvious by just editing the script and replace 1 with 0 and visa versa. But I doesn't work.
Any ideas?