Hello everybody!
I upgraded my Mac OS from Catalina to Monterey.
Since I have did that my program stops itself around 30 secondes.
Do I have to download a special library?
Do you have the same problem?
In this program click once and move mouse up and down, the the program send datas to a serial port
import processing.serial.*;
Serial DueSerialNativeUSBport141201; // The receive data port
Serial DueSerialSendUSBport141201; // The sending data port
int v1 =0;
int v2 =400;
int x;
int counterV1;
int oldv1;
//Record and repeat movement
int num = 20*4;
int numberSec = 4;
float mx[] = new float[num]; // Future
float my[] = new float[num]; // Future
float rx[] = new float[num];
float ry[] = new float[num];
int beginTime,endTime,TimeMiddleElapsed,LastTimeMiddleElapsed,Timer,Timer2,LastTimeElapsed;
int actualSec,lastSec, lastLastSec;
public void settings() {
size(600, 600, P3D);
}
void setup() {
// noStroke();
fill(255, 0, 0, 50);
println("Start Drawing!");
frameRate(45);
v1=counterV1=height/2;
// size(800,600);
// Open serial port
printArray(Serial.list());
DueSerialSendUSBport141201 = new Serial(this, Serial.list()[0], 9600);
// DueSerialNativeUSBport141201 = new Serial(this, Serial.list()[1], 9600);
// Read bytes into a buffer until you get a linefeed (ASCII 10):
// DueSerialNativeUSBport141201.bufferUntil('\n');
//draw with smooth edges:
//smooth();
background(255);
}
void draw() {
if (actualSec>lastSec){
lastLastSec=lastSec;
lastSec=actualSec;
}
actualSec = second(); // Values from 0 - 59
// print ( lastLastSec); print ( "last" ); print ( lastSec ); print ( "actual" ); println ( actualSec );
samplingMovement();
if (oldv1<v1 && v1!= oldv1 ){
counterV1++;
}
// Draw circles
fill(#ff0000);
ellipse(x, v1+height/2, 10, 10);
fill(#00ff00);
ellipse(x, oldv1-10, 5, 5);
// Update x position
x++;
// Refresh screen
if (x > 300) {
background(255);
x = 0;
}
int j = int(frameCount%(20*4));
String DueSerialSendUSBport141201Data ="<"
+ v2+"," + ry[j] + ">"; // cohesionCounterHigh // +orderCohesion+ ">";LevelCohesionToSend ","+ int (map ( LowLevelCohesionToSend, 0, 1, 0, 100))+
println(frameCount + ": " + " DueSerialSendUSBport141201Data " + ( DueSerialSendUSBport141201Data ));
DueSerialSendUSBport141201.write(DueSerialSendUSBport141201Data); // Send data to Teensy. only the movement
}
// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial DueSerialNativeUSBport101) { // receive 2 datas splited with ,
// read the serial buffer:
String myString = DueSerialNativeUSBport101.readStringUntil('\n');
// if you got any bytes other than the linefeed:
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
int values[] = int(split(myString, ','));
if (values.length > 0) {// v1 de 0 a 4000
oldv1=v1;
v1 = (int) map (values[0], 0, 4000, 0, 400);
v2 = (int) map (values[1], 0, 4000, 0, 400);
print (v1); print (" v1 "); println (v1);
print (v2); print (" v2 "); println (v2);
// println (counterV1);
}
}
void samplingMovement() {
int i = int(frameCount%(20*4));
if(frameCount>=0 && frameCount<=20*4+0 )
{
if(frameCount<=1) { // record 4 secondes
int timeElapsed= endTime-beginTime;
print (" timeElapsed"); println (timeElapsed);
beginTime=millis();
background(0);
}
// else background(0);
if(frameCount>0 ) //frameCount<=20*4+0
{
rx[i] = x;
// ry[i] = v1;
v2= (int) map (mouseY, 0, height, 0, 400);
ry[i] = v2;
mx[i] = rx[i];
my[i] = ry[i];
fill(255, 0, 0, 50);
circle(rx[i], ry[i], 10);
// print (frameCount); print (" ry "); print (i); print (" "); println (ry[i]);
}
}
if(frameCount>=20*4+1 ) // begin to replay
{
int TimeBack = millis();
int TimeBackElapsed = TimeBack -beginTime;
print (frameCount); print (" TimeMiddleElapsed "); println ( TimeBackElapsed);
circle(x+300, my[i], 10);
// print (frameCount); print (" ry' "); print (i); print (" "); println (ry[i]);
print (frameCount); print (" ry "); print (i); print (" "); print (ry[i]);
print (" my "); print (i); print (" "); println (my[i]);
}
if(frameCount>=2*20*4 && frameCount<=2*20*4+0 ) // && Timer2>=4000-20 end of replay // && actualSec>lastSec to synchronise with a second trigger
{
endTime=millis();
int timeElapsed= endTime-beginTime;
LastTimeElapsed= timeElapsed;
print (" LastTimeElapsed"); println (LastTimeElapsed);
Timer=0;
Timer2=0;
background(255);
// frameCount = -1; // Resets frameCount. -1 will run setup() again!
frameCount = 81; // Restart only recorded loop
// frameCount = 0; // Restart from beginning
}
// if (mousePressed==true && Timer<=20) {
if (mousePressed==true && frameCount>=0
) {
frameCount = 1; // Restart main loop better than frameCount = 0
}
}