Hey there! Sign in to join this conversationNew here? Join for free
x Turn on thread page Beta
    • Thread Starter

    I'm doing a game controller in processing and Arduino, I have the code for the game(space invaders) but I'm not really familiar with Arduino, I'm using only 3 push buttons in my arduino board, right , left and fire. The void loop in arduino is confusing me and also how to connect the arduino to processing. Right is connected to pin 11 and left is connected to pin 12 and fire is connected to pin 2
    Any help please!!!!
    Posted on the TSR App. Download from Apple or Google Play

    I'm not familiar with Arduino or Processing, but there's a quick guide to getting started here, have you seen this before?

    A good way to approach problems like this is just to try to solve the smallest and simplest problem as you possibly can at any one time, instead of trying to make everything work at once, so If you haven't managed to get Arduino and Processing to talk to each other yet, then it would be a good idea to do this first and test this on its own, then go back to the game and your push button controller once you're comfortable with that bit.

    As for reading pins, according to the docs, it seems like the function you need to check the state of a pin is called digitalRead()
    - https://www.arduino.cc/reference/en/...o/digitalread/

    Haven't heard of Processing looks pretty fun though.

    First things first start with the Arduino. We need to to read the state of your buttons.
    const int LEFTPIN = 11;
     const int RIGHTPIN= 12;
     const int FIREPIN= 2; 
       void setup() { 
    Serial.begin(9600); //set our serial port to Baudrate 9600
       void loop() { 
     bool leftButtonDown= digitalRead(LEFTPIN) == HIGH;
    bool rightButtonDown= digitalRead(RIGHTPIN) == HIGH; 
     bool fireButtonDown= digitalRead(FIREPIN) == HIGH; 
    First thing we do is read the state of each PIN and use it to identify if each button is pressed down or not.
    Then we write to the Serial Port at baud rate 9600 a text based command. To test open the Arduinos serial port monitor whilst the sketch is running and you should see the commands coming in when you press the buttons.

    How does the game get the commands you ask ? Via the Arduino Serial Port just like the serial port monitor.
    You need to modify your game in Processing to constantly read the Arduinos serial port(at baud rate 9600) looking for these commands and in turn map them to control the ship. How do I know what port number to listen on ? Open windows device manager - click Ports and you'l see the Arduino and its serial port number.
Submit reply
Turn on thread page Beta
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: February 22, 2018
How are you feeling about your exams?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.