NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Pygame (no rect object)
June 19, 2011 by missle3944 |
Hi All,
But when I substitute data as a variable in for Red it says that it is not a rect style object. But when I have x = 1 and x is red then it works fine. I know this is a very specific question but I've looked high and low for it. Here is my python code
-missle3944 |
---|---|
June 20, 2011 by hevans (NerdKits Staff) |
Hi missle3944, Couple of things seem strange to me in your program. First there is no main while loop, so your program is just going to run through once and exit, which is probably not what you want. I'm not a fan of your pygame.locals import *, its a little clearer too use pygame.Rect when you need to instantiate a Rect object. The documentation has the constructor for Rects taking either 4 or two arguments (left, top, width, height), or ((left, top), (width, height)). You have an extra 6 there at the end which I think is causing your current error. I also made the background white so I could see what is going on. The code below displays a red rectangle.
|
June 20, 2011 by missle3944 |
Hi Hevans, How would I do this? Should I do the conversion in python or in the MCU code? should I use a linear equation similar to the one used in the meat temp sensor project? Why does python not let me use a number from the serial port? is it becuase it thinks it is a string? -missle3944 |
June 22, 2011 by hevans (NerdKits Staff) |
Hi missle3944, My guess is that its not working when you do the read from the serial port (other than the fact that you were not doing it in a while loop) is that using the read() method of the file like pySerial interface reads exactly one byte from the serial port. This will work ok if you are sending exactly one byte over the serial port from your NerdKit. You will still have to turn it into an integer, then feed it to the data parameter. It might be useful to you to print the the value you get from the serial port to the command line from python, just so you get a better idea of what you are sending. Humberto |
June 22, 2011 by missle3944 |
Hi Humberto, I used the code that you sugessted and i just modified it alittle bit. But would it help if i only sent one byte at a time to python buy setting a delay on my nerdkit? Would it help if I placed a timeout on the serial side? I saw a guys code that he is doing the same thing I am but with an arduino but in python he used uspp and he used the read byte command instead of just read(). Is one integer one byte? I am very new to this binary and bits and byte thing. Heres my code if you have any suggestions:
-Dan |
Please log in to post a reply.
Did you know that a piezoelectric buzzer can be used in reverse as a microphone? Learn more...
|