Posts: 7
Threads: 1
Joined: Feb 2018
Hi,
I have an basic html page, with an input button that controls 2 step by step motors.
If I input the number 50, the motors will both open at half of course and this is perfect.
How can I make the motors to make 2, or 3, or 4 runs? right now I manage to make them run once.
p = lambda:None
p.__dict__ = json.loads(request.data)
concentration = int(p.concentration)
concentrationSteps = concentration*10
motors.rotate_motor('A', concentrationSteps, 1, 20)
motors.rotate_motor('B', concentrationSteps, 1, 20)
time.sleep(duration)
motors.rotate_motor('A', concentrationSteps, -1, 20)
motors.rotate_motor('B', concentrationSteps, -1, 20)
return "0";
Posts: 3,458
Threads: 101
Joined: Sep 2016
Posts: 7
Threads: 1
Joined: Feb 2018
A is the 1st motor, B is the 2nd motor. I was thinking about inputing a number from the keyboard and the motors should execute that number, for example if I enter 5, both the motors should run 5 times, opening and closing
Posts: 3,458
Threads: 101
Joined: Sep 2016
number_of_rotations = int(input("How many rotations? "))
for num in range(number_of_rotations):
# your current code here
Posts: 7
Threads: 1
Joined: Feb 2018
Thank you nilamo, I will post tomorrow updates with this.
Posts: 7
Threads: 1
Joined: Feb 2018
Feb-14-2018, 07:32 PM
(This post was last modified: Feb-14-2018, 07:32 PM by dnbbrain.)
No mather were I put
for num in range(number_of_rotations):
it gives IndentationError: expected an indented block.
Can't figure out were how to indent the for?
Posts: 3,458
Threads: 101
Joined: Sep 2016
https://docs.python.org/3/tutorial/contr...statements
You don't indent the for statement, you indent the block you're looping over.
Posts: 7
Threads: 1
Joined: Feb 2018
Feb-15-2018, 02:52 PM
(This post was last modified: Feb-15-2018, 02:52 PM by dnbbrain.)
from flask import Flask, render_template, request
import time
import ConfigParser
import motors
import json
app = Flask(__name__)
parser = ConfigParser.SafeConfigParser()
@app.route("/")
def main():
templateData = {
'pins' : 1
}
return render_template('main.html', **templateData)
@app.route("/start-admission", methods = ['POST'])
def start_admission():
print request.data
p = lambda:None
p.__dict__ = json.loads(request.data)
concentration = float(p.concentration) #input a number to proceed
concentrationSteps = concentration*10
volumeI = 100
volumeII = 150
p_volumeI = float(volumeI*p.concentration)/66
p_volumeII = float(volumeII*p.concentration)/66
duration = int(p.duration)
speed = int(p.speed)
admissionSteps = 1000/speed
number_of_rotation_1 = float(p_volumeI) #must execute the nr of turns p_volumeI
for num in range(number_of_rotation_1):
motors.rotate_motor('A', concentrationSteps, 1, 20)
motors.rotate_motor('B', concentrationSteps, 1, 20)
time.sleep(duration)
number_of_rotation_2 = float(p_volumeII) #must execute the nr of turns p_volumeII
for num in range(number_of_rotation_2):
motors.rotate_motor('B', concentrationSteps, -1, 20)
motors.rotate_motor('A', concentrationSteps, -1, 20)
return "0";
if __name__ == "__main__":
app.run(host='0.0.0.0', port=9000, debug=True) still the same IndentationError: expected an indented block.
Posts: 7,080
Threads: 122
Joined: Sep 2016
Feb-15-2018, 04:59 PM
(This post was last modified: Feb-15-2018, 04:59 PM by snippsat.)
(Feb-15-2018, 02:52 PM)dnbbrain Wrote: still the same IndentationError: expected an indented block. You most indent code under line 36 and line 44.
My guess.
from flask import Flask, render_template, request
import time
import ConfigParser
import motors
import json
app = Flask(__name__)
parser = ConfigParser.SafeConfigParser()
@app.route("/")
def main():
templateData = {
'pins': 1
}
return render_template('main.html', **templateData)
@app.route("/start-admission", methods=['POST'])
def start_admission():
print request.data
def p(): return None
p.__dict__ = json.loads(request.data)
concentration = float(p.concentration) # input a number to proceed
concentrationSteps = concentration * 10
volumeI = 100
volumeII = 150
p_volumeI = float(volumeI * p.concentration) / 66
p_volumeII = float(volumeII * p.concentration) / 66
duration = int(p.duration)
speed = int(p.speed)
admissionSteps = 1000 / speed
# must execute the nr of turns p_volumeI
number_of_rotation_1 = float(p_volumeI)
for num in range(number_of_rotation_1):
motors.rotate_motor('A', concentrationSteps, 1, 20)
motors.rotate_motor('B', concentrationSteps, 1, 20)
time.sleep(duration)
# must execute the nr of turns p_volumeII
number_of_rotation_2 = float(p_volumeII)
for num in range(number_of_rotation_2):
motors.rotate_motor('B', concentrationSteps, -1, 20)
motors.rotate_motor('A', concentrationSteps, -1, 20)
return "0"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=9000, debug=True)
Posts: 7
Threads: 1
Joined: Feb 2018
Feb-15-2018, 07:22 PM
(This post was last modified: Feb-15-2018, 07:22 PM by dnbbrain.)
It was so simple jezz, just used TAB and was ok, so it should do some calculus, if I enter 3 the first motor should do 4.5 runs, clockwise - counter clocwise, and the second motor should do 6.8 runs open - close, instead they run like non stop, like in a loop. Any ideeas? Thank you
|