Page 1 of 1

make me when key pressed

Posted: Tue Mar 06, 2018 11:36 pm
by jakerthegamer3
can some one make a key pressed run this that is simple and i can add my code to it and understand it
this is the code im working with


Code: Select all

import RPi.GPIO as GPIO


import time


GPIO.setmode(GPIO.BOARD)


pin_number = 12
GPIO.setup(pin_number, GPIO.OUT)

 
frequency_hertz = 50
pwm = GPIO.PWM(pin_number, frequency_hertz)


left_position = 0.40
right_position = 2.5
middle_position = (right_position - left_position) / 2 + left_position


positionList = [left_position, middle_position]


ms_per_cycle = 1000 / frequency_hertz



for position in positionList:
		duty_cycle_percentage = position * 100 / ms_per_cycle
		print("Position: " + str(position))
		print("Duty Cycle: " + str(duty_cycle_percentage))
		print("")
		pwm.start(duty_cycle_percentage)
		time.sleep(.5)
	


pwm.stop()


GPIO.cleanup()

Re: make me when key pressed

Posted: Wed Mar 07, 2018 12:23 pm
by pcmanbob
Hi.

First when posting code please use code tags.

Add [code] at the top

code goes here

and [/code] at the bottom.

second your request for help is some what vague, do you want to run the program and then wait for a specific key to be pressed, or are you wanting to make the key press start the program say from the desktop.

please be more specific in your request.

Re: make me when key pressed

Posted: Wed Mar 07, 2018 5:22 pm
by mahjongg
added code tags.