Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
pipporisso
pipporisso's Profile
2
Posts
2
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Store a function into the array and recall it
[8 Replies]
25-Jun-2013 09:39 AM
Forum:
Programming Questions
Hi guys.. I have to ask you something... If I store a function into an exact index of an array, how can I recall it?
For example:
v[1]=stroke(0);
If I write in the code
v[1];
It runs the function stored into it?
If it doesn't work, how can I do something similar?
Problem with reading a byte from the serial port
[2 Replies]
15-Jun-2013 08:13 AM
Forum:
Integration and Hardware
Hi guys.
I've tried several solutions for this problem but I can't reach my target.
I'm creating an electronic drum with Arduino.
The code in Arduino works well so I haven't problems in it.
Then I transmit the byte I've assembled in a program written in Processing (from the serial port) but there is something wrong.
Sometimes Processing gives me some errors or it works but in the wrong way.
I've got some problems with reading the byte from Arduino and discompose it in a string of 8 bit.
This is my code in Processing with some extra information because I tried other solutions in the same code:
import processing.serial.*;
import ddf.minim.*;
PImage img;
Minim minim;
AudioSnippet snare,hiHat,tomH,tomM,floorT,crash;
String SPORT = Serial.list()[1];
Serial port;
boolean limit=false;
int PADres;
int hwe=10;
int[] v = new int[7];
/*int v[2]={1,2};
int i=1;*/
void setup(){
for(int i=0;i<7;i++) {
v[i]=0;
}
port = new Serial(this, SPORT, 9600);
port.bufferUntil('\n');
size(600, 600);
img = loadImage("drum.jpg");
background(img);
minim = new Minim(this);
/*if(port.available()>0){
snare = minim.loadSnippet("kit"+v[i]+"/snare.wav");*/
snare = minim.loadSnippet("kit1/1snare.wav");
tomH = minim.loadSnippet("kit1/2tomhigh.wav");
tomM = minim.loadSnippet("kit1/3tommed.wav");
floorT = minim.loadSnippet("kit1/4floortom.wav");
hiHat = minim.loadSnippet("kit1/5hihat.wav");
crash = minim.loadSnippet("kit1/6crash.wav");
}
/*void draw(){
serialEvent(port);
}
void serialEvent (Serial miaporta) {
String PADres = port.readStringUntil('\n');
if (PADres != null) {
PADres = trim(PADres);
float inByte = float(PADres);
byte dati = byte(inByte);
for(int i=0;i<7;i++) {
converti(dati);
}
if (port.available() > 0){
//byte(PADres);
//dati=PADres;
//PADres=PADres>>2;
if(v[0]==1){//if((dati&00000001)==1){
stroke(0);
ellipseMode(CENTER);
ellipse(250,280,hwe,hwe);
snare.play();
snare.rewind();
}else if(v[0]==0){
stroke(1);
ellipseMode(CENTER);
ellipse(250,280,hwe,hwe);
}
if(v[1]==1){//if((dati&00000010)==2){
stroke(0);
ellipseMode(CENTER);
ellipse(284,213,hwe,hwe);
tomH.play();
tomH.rewind();
}else{
stroke(1);
ellipseMode(CENTER);
ellipse(284,213,hwe,hwe);
}
if(v[2]==1){//if((dati&00000100)==4){
stroke(0);
ellipseMode(CENTER);
ellipse(370,210,5,5);
tomM.play();
tomM.rewind();
}else{
stroke(1);
ellipseMode(CENTER);
ellipse(370,210,hwe,hwe);
}
if(v[3]==1){//if((dati&00001000)==8){
stroke(0);
ellipseMode(CENTER);
ellipse(410,285,hwe,hwe);
floorT.play();
floorT.rewind();
}else{
stroke(1);
ellipseMode(CENTER);
ellipse(410,285,hwe,hwe);
}
if(v[4]==1){//if((dati&00010000)==16){
stroke(0);
ellipseMode(CENTER);
ellipse(150,200,hwe,hwe);
hiHat.play();
hiHat.rewind();
}else{
stroke(1);
ellipseMode(CENTER);
ellipse(150,200,hwe,hwe);
}
if(v[5]==1){//if((dati&00100000)==32){
stroke(0);
ellipseMode(CENTER);
ellipse(215,105,hwe,hwe);
crash.play();
crash.rewind();
}else{
stroke(1);
ellipseMode(CENTER);
ellipse(215,105,hwe,hwe);
}
}
}
}*/
void draw(){
//int dati=PADres;
//PADres[0]=0;
//println(Serial.list());
if (port.available() > 0){
for(int i=0;i<7;i++) {
v[i]=0;
}
PADres=port.read();
for(int i=0;i<7;i++) {
converti(PADres);
}
//byte(PADres);
//dati=PADres;
//PADres=PADres>>2;
if(v[0]==1){//if((PADres&00000001)==1){
stroke(0);
ellipseMode(CENTER);
ellipse(250,280,hwe,hwe);
snare.play();
snare.rewind();
}else if(v[0]==0){
stroke(1);
ellipseMode(CENTER);
ellipse(250,280,hwe,hwe);
}
if(v[1]==1){//if((PADres&00000010)==2){
stroke(0);
ellipseMode(CENTER);
ellipse(284,213,hwe,hwe);
tomH.play();
tomH.rewind();
}else if(v[1]==0){
stroke(1);
ellipseMode(CENTER);
ellipse(284,213,hwe,hwe);
}
if(v[2]==1){//if((PADres&00000100)==4){
stroke(0);
ellipseMode(CENTER);
ellipse(370,210,5,5);
tomM.play();
tomM.rewind();
}else if(v[2]==0){
stroke(1);
ellipseMode(CENTER);
ellipse(370,210,hwe,hwe);
}
if(v[3]==1){//if((PADres&00001000)==8){
stroke(0);
ellipseMode(CENTER);
ellipse(410,285,hwe,hwe);
floorT.play();
floorT.rewind();
}else if(v[3]==0){
stroke(1);
ellipseMode(CENTER);
ellipse(410,285,hwe,hwe);
}
if(v[4]==1){//if((PADres&00010000)==16){
stroke(0);
ellipseMode(CENTER);
ellipse(150,200,hwe,hwe);
hiHat.play();
hiHat.rewind();
}else if(v[4]==0){
stroke(1);
ellipseMode(CENTER);
ellipse(150,200,hwe,hwe);
}
if(v[5]==1){//if((PADres&00100000)==32){
stroke(0);
ellipseMode(CENTER);
ellipse(215,105,hwe,hwe);
crash.play();
crash.rewind();
}else if(v[5]==0){
stroke(1);
ellipseMode(CENTER);
ellipse(215,105,hwe,hwe);
}
}
}
void stop(){
snare.close();
hiHat.close();
tomH.close();
tomM.close();
floorT.close();
crash.close();
minim.stop();
super.stop();
}
void converti(int n){
int z=n;
for(int i=0;i<7 && z!=0;i++){
v[i]=z%2;
z=z/2;
}
}
I'm going to marry the person who solve my problem... Please :(
«Prev
Next »
Moderate user : pipporisso
Forum