Final Project Progress – Thais And Armaan

Updated Project Idea:

Our project idea has been modified a bit now and is about creating a driving experience for the user in which the user chooses a circuit in processing and uses a joystick to drive a car (made using arduino) and attempts to finish the circuit shown on their processing screens.

For this week, we managed to figure out how to make the core of our project work. We found out a way to use a joystick as an input and then send that information to processing which then communicates it to the Arduino causing a change in it which we can then use as an output. This was actually so time consuming and we had to wrap our brains around how we could make this possible but eventually we found a library on processing called Game Control Plus and G4P which allowed us to configure processing so that we can design what each button in our joystick would do and this would be stored as a separate library which we could then import into our main processing code and use within it.

Meanwhile, we also started working on our processing interface and set up the following game screens:

 

menu()
  • Contains the main menu for the game in which the player can choose to play the game or read the instructions or change settings
choose_circuit()
  • The playable component of the game wherein the player chooses the circuit they want to race their car in
instruction()
  • Details game instructions
setting()
  • To change game settings
gameover()
  • To signify end of game

Code

The following is the code that we have written till now:

 

For the Joystick:

 

int ledPin = 4;
 
float brightness = 0;
 
void setup() {
  Serial.begin(9600);
  Serial.println("0");
  pinMode(ledPin, OUTPUT);
}
 
void loop() {
  while (Serial.available()) {
    //get the brightness value from processing
    brightness = Serial.parseFloat();
    
    if (Serial.read() == '\n') {
    //turn on the LED with the given brightness
      analogWrite(ledPin, brightness);
      Serial.println(brightness);
    }
  }
}

 

Arduino code to test out the effect of a joystick on an LED light and toggle it on or off

 

import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;

import processing.serial.*;

Serial myPort;

ControlDevice cont;
ControlIO control;

float press;

void setup()
{


  size(360, 200);
  control = ControlIO.getInstance(this);
  cont = control.getMatchedDevice("LED_Input");

  if (cont == null)
  {
    println("not today champ");
    System.exit(-1);
  }
  
  
   printArray(Serial.list());
  String portname=Serial.list()[0]; 
  println(portname);
  myPort = new Serial(this, portname, 9600);
  myPort.clear();
  myPort.bufferUntil('\n');
}

void draw()
{
  background(press);
  getInput();
}

public void getInput()
{
  press = map(cont.getSlider("analog").getValue(), -1, 1, 0, 255);
  println(press);
}


 
void serialEvent(Serial myPort) {
  String s=myPort.readStringUntil('\n');
  s=trim(s);
 
  //write brightness so that Arduino can use it
  myPort.write(press + "\n");
}

We also created a library called “LED_Input” using the GCP Configurator Example of the GCP Library

 

Housekeeping

  • We set up a notion page to better manage our work flow
    • https://www.notion.so/Final-Notes-b013a1ba19a4439a9d9836da5b183881
  • We sit up a github repo to better manage our coding work flow.
    • https://github.com/Armaan-Agrawal/Intro_To_IM_Final

Finally, here is a short video showing the joystick and its interaction with arduino…. and also our excitement :))

Leave a Reply