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";
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
number_of_rotations = int(input("How many rotations? "))
for num in range(number_of_rotations):
# your current code here
Thank you nilamo, I will post tomorrow updates with this.
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?
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.
(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)
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