Python If Statement Issues
Date | 2016-03-01 07:32 |
From | Emmett Palaima |
Subject | Python If Statement Issues |
Hi, I was recently using python with csound on the raspberry pi to read some control values off the digital inputs. I was using some nested if statements to make it so that a button would toggle the control value between 0 and 1. It wasn't working in my csd despite everything else compiling and running fine, so I isolated it in python. The only part that doesn't is the nest if statements that are supposed to make it toggle between the two values, it always prints 0.0 instead of switch between 1.0 and 0.0. I've included my code, Does anyone see anything wrong?
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP) a = 0.0 b = 0.0 c = 0 while True: if(GPIO.input(4) ==1 and c ==0): print 'Button 1 Pressed' if(a ==0.0): a = 1.0 if(a == 1.0): a = 0.0 c = 1 print a if(GPIO.input(4) !=1): c = 0 if(GPIO.input(24) ==0): print 'Button 2 Pressed' |
Date | 2016-03-01 08:43 |
From | Bernt Isak Wærstad |
Subject | Re: Python If Statement Issues |
On 1 March 2016 at 08:32, Emmett Palaima <epalaima@berklee.edu> wrote:
I think the problem is that you need a else if on the second if check there. As a side note/suggestion - for the COSMO Project (http://cosmoproject.github.io/) we run Csound through the python API sending values from the GPIO to Csound through channels (see example here: https://github.com/cosmoproject/cosmohat-fw/blob/master/csndPython_SPI_test.py). It would clean up the Csound code and also easier to test and debug the python code. Mvh.
Bernt Isak Wærstad |
Date | 2016-03-01 09:05 |
From | Francois PINOT |
Subject | Re: Python If Statement Issues |
Or a simpler way: a = 1 - a 2016-03-01 9:43 GMT+01:00 Bernt Isak Wærstad <berntisak@gmail.com>:
|
Date | 2016-03-02 05:38 |
From | Emmett Palaima |
Subject | Re: Python If Statement Issues |
Thanks for the help! Both ways work great. The python stream looks like a really good method, I'll have to look into it more. Is there a particular way you have to format your csd to work with code like this? On Tue, Mar 1, 2016 at 4:05 AM, Francois PINOT <fggpinot@gmail.com> wrote:
|