Radio code (sound and Arduino)

possibly you want concentrate on a processing code and make a good show,
so you not too fit / or even interested into

  • arduino code and
  • tricky serial communication

i can suggest to use
GitHub - firmata/arduino: Firmata firmware for Arduino ,
means you just upload a ready sketch to arduino,
and on processing side start with a example from lib
Arduino Playground - HomePage
install lib: Arduino Firmata v9 ( and close open IDE )

Files / Examples / Contributed Libraries /

Arduino ( Firmata ) / arduino input /

as a start i cut it down

/*arduino_input*/
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;

void setup() {
  size(470, 280);
  println(Arduino.list());  
  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list
  // printed by the line above).
  arduino = new Arduino(this, Arduino.list()[0], 57600);
}

void draw() {
   println(arduino.analogRead(0));  //Ain 0
}

so you get integer numbers 0 … 1023 ( range of arduino Ain )
and in processing can do with it what you want.

example:
arduino example select:


arduino upload:

new processing code with select 3

/*arduino_input*/
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
String arduinoport = Arduino.list()[1];
int sel, vAin0;

void setup() {
  size(1024, 280);
  println(Arduino.list());  
  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list printed by the line above).
  println("try connect to "+arduinoport);
  arduino = new Arduino(this, arduinoport, 57600);
}

void draw() {
  background(200, 200, 0);
  arduino_read();
  select_of_three();
}

void select_of_three() {
  int lim12 = 340, lim23 = 680;
  if ( vAin0 >= 0     && vAin0 < lim12 ) sel = 0; 
  if ( vAin0 >= lim12 && vAin0 < lim23 ) sel = 1; 
  if ( vAin0 >= lim23 && vAin0 < 1024 )  sel = 2;
  fill (0,200,0);
  stroke(0,0,200);
  rect (sel * lim12, 10, lim12, height-40);
}

void arduino_read() {
  vAin0 = arduino.analogRead(0);  //Ain 0
  stroke(200, 0, 0);
  line( vAin0, height-10, vAin0, height-20);
  if ( keyPressed ) println("read vAin0: "+vAin0);
}

1 Like