Uhh… my attempts at trying to fix my assignment have backfired. It no longer works (with the “fix-in-progress” code). I’m probably going to have to start the fixing from scratch now. Damn it. At least I had a (somewhat buggy) thing to submit on time.
Ok, so I have it so the button works a lot better now. At least sometimes. I think there may be an issue with what data is actually being sent between the programs, I have arduino sending a byte but processing receives an int, and I think something is being lost in translation. I didn’t end up needing a serialEvent(), I just had to restructure some of my arduino code to only write under a certain condition. Unfortunately, that also broke the serendipitous flashing of the ingredient images to indicate that they are selected. I am just trying to figure out how to at least get the selected image to display consistently instead of just flashing once. The LEDs are much faster and don’t lag behind anymore though. Oh, and I also had to manually map the values for my potentiometer because they were not really accurate as to approximate quarters of the knob, and the values got really finicky.
I am making progress, but this is exactly why I didn’t want to try to do this before handing it in – it worked well enough on the due date.
Edit: after re-reading this, I had an idea. If I create a variable in processing that doesn’t directly receive the input data, but stores the value of the variable that does, maybe that will alleviate my issue. Or maybe that could be accomplished with the serialEvent(). I haven’t looked into it overly well yet, as I found most of my issue resolution in arduino.
Haha whoops! In my attempt to get everything ready for submission, I totally blanked on posting the completed thing on my blog.
So, here is a video of the game working and me playing through it:
I’m proud of the amount of work I managed to to in order to hand this in on time. I also really like the graphics I wound up making for the game. I used a program called Aseprite to make them. It is specifically designed to make pixel art and sprites for games. I am still figuring it out, though. The program also has it’s issues – you’ll notice that the LEDs are really lagging behind. They were supposed to provide real-time feedback on what the user was doing in the game.
But, it is complete. I am not 100% happy with how it turned out, because it doesn’t function as well as I would like it to. I think it’s an issue with the frequency of communication. I think it’s an issue where the arduino and processing are basically just sending each other a constant stream of data, and I need to make it so it only sends when the value changes, so it won’t send the same value from holding the buttons down. I’m theorizing that this solution I have thought of will fix it, and it seems like the serialEvent() function will help facilitate this.
I was also, as previously noted, unable to figure out how to do animated gifs in processing in a reasonable amount of time that didn’t involve loading each individual frame as I was already having issues with lag from at least one side of the code. This is what the game background was supposed to look like:
I am going to try to code my fix into it to improve the functionality over reading week – I didn’t have time to do that before handing it in as I was pretty sure it would require a major overhaul of my code and did not have the time to re-code everything.
I have officially finished all of my coding and such! My arduino is talking to my code, the code is done and it all works! Huzzah! I just need to make the graphics and such, but it works! Worst comes to worst, I can submit as is with a lot of instructions, haha. The LEDs are a little slow to react, so it does kind of impact the functionality of the game, but I can live with that for now.
Off to bed with me now! I can go to sleep happy!
Whoops! Forgot the schematic and parts list when I uploaded the breadboard wiring diagram.
- Red LED x 1
- Green LED x 1
- Blue LED x 1
- 330 Ω Resistor x 3
- 10K Ω Resistor x 1
- Potentiometer x 1
- Push Button x 1
- Jumper Wires (Various Colors) x 10
- I used:
- Red x 3
- Green x 1
- Blue x 1
- White x 2
- Black x 3
I’ve got a reasonably easy setup here. I’m not 100% sure if I selected the correct potentiometer, but it has 3 pins and is approximately the right size, so I’m not picky. I had a hell of a time getting Fritzing to work on my computer though. After some intensive Googling, I found that the program has a nasty habit of not indicating if it is still loading things and will just freeze if you try to do anything (even just moving the window). I had fun trying to get everything on there in a way where it looks tidy and you can see all of the parts! And the white wire versus yellow wire is purely aesthetic. Yellow is one of my least favorite colors. I need to get some purple wires, haha.
OK, so I think I am going to give up on using animated gifs for the game graphics. It wasn’t a functional thing, more of an aesthetic thing, so I don’t have to do a major overhaul of my idea or anything like that. I’m just a little disappointed.
Processing has no built in way to display pre-animated gifs. I looked for libraries that I could use to display an animated gif as well, but sadly I could not find one to suit my purposes. I tried making a for loop to load and display each individual frame, but it didn’t work. I did find an example here, but I need a little bit more time for a refresher on processing before I can implement something like that.
But, like I said, it is only aesthetic. And maybe this was a good thing. It will take me a lot less time to do stationary graphics versus animated. And who knows, once I finish this off and have some more time, maybe I can look into adding those animated gifs.