, , , ,

The next step would be allowing the user to select how many times the pills have to be dispensed. This could be useful when the same pills are dispensed for many patients. The idea was to let the user to select a number using “spinner” by jQuery UI. The code is as follow:

var spinner = $( "#spinner" ).spinner();
$("#spinner").spinner({min: 1, max: 10}); //to set min and max value for spinner
//get the value in the input
var amount = $('#spinner').val();
//post the data with the pilltype
$.post('', {pilltype:combo, amount:amount}).done(function (dispensed) {

At the Python side, convert the data into integer and use a while loop to repeat the movements.

        amount = data.get("amount", None) 
        amount2 =int (amount) #to convert the above unicode "amount" into integer

        count = 0
        while (count < amount2):

            if pilltype == "A":
                    pigpio.set_servo_pulsewidth(servos[0], 900) 
                    pigpio.set_servo_pulsewidth(servos[0], 1500) 
                    print "Dispensed A!"
            count = count +1

See the demo video here: