Dear forum
I'm working on some projects inculding processing and came to problem I can't nor find any informations on how to solve them.
The scenario:
Processing got 4 faders which send their values continously to the arduino in 4 different bytes. The arduino takes those values and stores them in an arraylist which then put in another function which includes delays. At this point the problem beginns, because there is no beginning nor and end so after the function with the delays haft passed, the arduino starts to store the values not from the beginning.
The arduino code to store the values:
void serial()
{
if(Serial.available())
{
counter = 0;
anfang = Serial.read();
if(anfang == 'H')
{
while(counter < 4)
{
byteincomming[counter++] = Serial.read();
}
}
ton1 = map(byteincomming[0], 0, 255, 300, 500);
ton2 = map(byteincomming[1], 0, 255, 300, 500);
ton3 = map(byteincomming[2], 0, 255, 300, 500);
ton4 = map(byteincomming[3], 0, 255, 300, 500);
}
}
The arduino funuction with the delays:
void Ton()
{
if(an == true || dauer == true)
{
tone(toner, ton1);
delay(300);
tone(toner, ton2);
delay(300);
tone(toner, ton3);
delay(300);
tone(toner, ton4);
delay(300);
an = !an;
}
else noTone(toner);
}
The processing code:
import processing.serial.*;
Schieberegler[] regler = new Schieberegler[4];
Serial port;
void setup()
{
background(255);
size(500, 500);
smooth();
port = new Serial(this, Serial.list()[1], 9600);
for(int i = 0; i < regler.length; i++)
{
regler[i] = new Schieberegler((width / regler.length) * (i+ 0.5), 250, i);
}
}
void draw()
{
background(255);
for(int i = 0; i < regler.length; i++)
{
regler[i].fadenzeigen();
regler[i].schieben();
regler[i].kugelzeigen();
regler[i].wertanzeigen();
}
}
class Schieberegler
{
float x, yfaden;
float ykugel;
float hoehe = 100;
int wert;
int platz;
Schieberegler(float xpos, float ypos, int posi)
{
x = xpos;
yfaden = ypos;
ykugel = ypos;
platz = posi;
}
void fadenzeigen()
{
fill(0);
ellipse(x, yfaden, 4, hoehe);
}
void kugelzeigen()
{
fill(255);
ellipse(x, ykugel, 10, 8);
}
[b] void schieben()[/b]
{
if(mouseX > x - 4 && mouseX < x + 4 && mouseY > yfaden - hoehe/2 && mouseY < yfaden + hoehe/2 && mousePressed && mouseButton == LEFT) // Value is created
{
ykugel = mouseY;
wert = int(map(ykugel, yfaden - hoehe/2, yfaden + hoehe/2, 255, 0));
}
}[b]
void wertanzeigen() // Serial out[/b]
{
if(platz == 0) port.write('H');
port.write(wert);
}
}
I realy have no idea how to put an beginning byte and an ending one, so could you give me a quick reference? Because I'm sure this been discussed befor.
Thanks in advance
bluebubble