jakerthegamer3
Posts: 12
Joined: Sun Mar 04, 2018 6:50 pm

make me when key pressed

Tue Mar 06, 2018 11:36 pm

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()

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: make me when key pressed

Wed Mar 07, 2018 12:23 pm

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.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13142
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: make me when key pressed

Wed Mar 07, 2018 5:22 pm

added code tags.

Return to “Python”