Tags

, , , , ,

The idea is to let the user selects the types of pill using checkboxes. RaspiCare will then dispense the right type of pill accordingly.

So when the “Dispense” button on the web app is clicked, the jQuery function will go through each checkbox and check their “checked” status. For those that are checked, the value will be “pushed” into the array variable called “selection”. Then their values are combined as a variable “combo”. This variable will be “posted” to Python function called “dispense”. The codes are as follow:

$('#dispense').click(function(){
	var selection=[];
	$(':checkbox:checked').each(function(){
		selection.push(this.value);
	});
	var combo = selection.join('');
	
	$('#testing').empty().append('Checked value: '+combo +' x '+amount);  
	$.post('http://172.20.194.122:8080/dispense', {pilltype:combo}).done(function (dispensed) {
		$('#testing2').empty().append(dispensed);
	});							
});

At the Python side, get the data and do some if-else statements. Awesome it works. Something like this:

 @cherrypy.expose
    def dispense (self, **data):

        import pigpio
        import time

        servos=[4,7] #GPIO number
        pigpio.start()
        pilltype = data['pilltype']

            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!"
                  
            elif pilltype == "B":
                    pigpio.set_servo_pulsewidth(servos[1], 900) 
                    time.sleep(1)
                    pigpio.set_servo_pulsewidth(servos[1], 1500) 
                    time.sleep(1)
                    print "Dispensed B!"

Connection as follow:

Connecting to the servo :)

Connecting to the servo 🙂


So here is the demo video:

Advertisements