BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: project 001 servo multiway controller

Thu Aug 27, 2015 7:04 am

As Joan Said, the Magpi is good, but another convenient source of information is http://www.google.co.uk

turn on a LED

program a button or switch as an input
Doug.
Building Management Systems Engineer.

davezx
Posts: 43
Joined: Wed Jul 01, 2015 9:52 pm

Re: project 001 servo multiway controller

Thu Aug 27, 2015 9:48 am

I've been looking on Google a lot.
There are some threads which people have asked for help for the same as what I'm wanting to do but when they ask for help all the answers just confuse the person asking the question.
The closest one I've found was on the arduino forum which a bloke wants a program to
Move a device from A-B and stay there.
Be able to stop/pause mid travel
Adjust forward/backward mid travel.
Use end limit switches at either side.
Use push buttons.

He's got some advice but the thread doesn't go to completion of project to see if it worked or not.
Surely it would be better if someone had a script to make this work it would be better to post it so it can be copied/typed up rather than having the bloke tearing his hair out trying to work How to write it.

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: project 001 servo multiway controller

Thu Aug 27, 2015 9:57 am

BMS Doug gave you suggested steps.

How far did you get?

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: project 001 servo multiway controller

Thu Aug 27, 2015 10:23 am

davezx wrote:I've been looking on Google a lot.
There are some threads which people have asked for help for the same as what I'm wanting to do but when they ask for help all the answers just confuse the person asking the question.
The closest one I've found was on the arduino forum which a bloke wants a program to
Move a device from A-B and stay there.
Be able to stop/pause mid travel
Adjust forward/backward mid travel.
Use end limit switches at either side.
Use push buttons.

He's got some advice but the thread doesn't go to completion of project to see if it worked or not.
Surely it would be better if someone had a script to make this work it would be better to post it so it can be copied/typed up rather than having the bloke tearing his hair out trying to work How to write it.
We (and the arduino forumites) want to help you to learn how to do this, not to do all the work for you. So we post suggestions and guidelines and if you post your code we will give advice on that.

I have completed the first three steps using code copied and pasted from websearch, these examples should probably work.

Both Joan and I would prefer that you not read the examples below and instead try to figure out your own solutions.



Stage 1:
Have a program that registers when a button is pushed.

Code: Select all

Please try to find your own solution before reading














import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    input_state = GPIO.input(18)
    if input_state == False:
        print('Button Pressed')
        time.sleep(0.2)

GPIO.cleanup()
Stage 2:
have a program that will drive an LED on for 10 seconds.
start with the sample code from the page above which turns an LED on and off.

Code: Select all

Please try to find your own solution before reading














import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

while (True):
    GPIO.output(18, True)
    time.sleep(0.5)
        GPIO.output(18, False)
        time.sleep(0.5)
modify it to run once, turning the LED on for 10 seconds then stop.

Code: Select all

Please try to find your own solution before reading














import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

GPIO.output(18, True)
time.sleep(0.5)
GPIO.output(18, False)
        
GPIO.cleanup()
Stage 3:
Have program that registers button push and turns on LED for 10 seconds. combine two codes above (I needed to change GPIO allocation as they used the same pin in both examples).

Code: Select all

Please try to find your own solution before reading














import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.OUT)
while True:
    input_state = GPIO.input(18)
    if input_state == False:
        print('Button Pressed')
        GPIO.output(17, True)
        time.sleep(10)
        GPIO.output(17, False)

GPIO.cleanup()
Doug.
Building Management Systems Engineer.

davezx
Posts: 43
Joined: Wed Jul 01, 2015 9:52 pm

Re: project 001 servo multiway controller

Thu Aug 27, 2015 12:47 pm

Thank you for the help on them. I will try to have a work on some coding before I look on them.
I understand that you would prefer people to learn and I will with projects going forward.
This one tho I was hoping to be able to get it ready for a car show that's on in a few weeks which is why I was hoping to get the right code for it as it's not just the programming I've got to find time for but I've got to fabricate the holder and all other parts associated with it to fit it in the car which will take at least a week to do with fibreglassing and finishing and wiring into the car.

Return to “General discussion”