SNES Controller Communicating with Processing

edited January 2014 in Arduino

Hello! New member here!

I'm still relatively new to using Processing and Arduino and I'm trying to figure out how to make my SNES controller, which is connected to an Arduino board, interact with my Processing program. The idea is to make shapes expand while simultaneously playing a musical note. Here's a simple diagram of what I want to accomplish:

Minor_controls_1

Here's the code for the Arduino program: http://inf.ufrgs.br/~rgsilva/dokuwiki/doku.php?id=public:hardware:snes

And the code in my Processing program is pasted below.

It's already connected to the Processing sketch via the port, but instead of interacting with the program, it prints out a series of numbers when even a single button is pressed (eg 224, 224, 224, 0, 0, 224). What would be the best way(s) of going around this and to ensure that the controller works with the program?

Thank you.

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;     // Data received from the serial port

int ell1 =50;
int ell2 =100;
int ell3 =150;
int ell4 =200;
int ell5 =250;


void setup() {

  size(500, 400);
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 57600);

}

void circles() { 


  fill(255, 0, 0);
  ellipse(width/2, height/2, ell5, ell5);
  fill(0, 255, 0);
  ellipse(width/2, height/2, ell4, ell4);
  fill(0, 0, 255);
  ellipse(width/2, height/2, ell3, ell3);
  fill(255, 255, 0);
  ellipse(width/2, height/2, ell2, ell2);
  fill(0, 0, 99);
  ellipse(width/2, height/2, ell1, ell1);
}


void draw() {
  circles();

 if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
    println(val);
  }


//    while ((ell4<400) && (ell3<250) && (val=20) {
//      ell4=ell4+1;
//      ell3=ell3+1;
//    }
//
//else { 
//  background(0);
//  ell1 =100;
//  ell2 =150;
//  ell3 =200;
//  ell4 =250;
//  circles();
//}
}

Answers

  • What you are telling the processing program is to draw circles(); And since draw is a loop it will fill and draw those ellipses in a loop. I know that the Arduino will send the codes in a bit or max 255 values. What you need is to capture the int val numbers and set some ifs inside circles().

Sign In or Register to comment.