Tags

, , , ,

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('http://172.20.194.122:8080/dispense', {pilltype:combo, amount:amount}).done(function (dispensed) {
	$('#testing2').empty().append(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) 
                    time.sleep(1)
                    pigpio.set_servo_pulsewidth(servos[0], 1500) 
                    time.sleep(1)
                    print "Dispensed A!"
            count = count +1

See the demo video here:

Advertisements