Eliminating the blinking
in
Programming Questions
•
5 months ago
Hello,
I have this code in arduino, and i am trying to draw visuals in processing, responding to the values coming in arduino per second, which makes my visual blink every second. What can be done to make it smoother or consistant. Plz help. The codes are as follows:
Here`s my arduino code:
#include <Brain.h>
// Set up the brain parser, pass0 it the hardware serial object you want to listen on.
Brain brain(Serial1);
void setup() {
// Start the hardware serial.
Serial1.begin(9600); //moved from brain (init)
Serial.begin(9600);
Serial.println("ready");
}
void loop() {
// Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"
if (brain.update()) {
Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
}
}
And here`s my processing code:
import processing.serial.*;
Serial myPort;
int channels = 10;
int [] channel = new int[channels];
int packetCount = 0;
//float easing=1;
//int last;
//int millis();
void setup() {
size(1200, 1000);
println(Serial.list());
String portName= Serial.list() [0];
myPort= new Serial(this, portName, 9600);
myPort.bufferUntil(10);
background(0);
smooth();
noFill();
stroke(160);
frameRate(60);
}
void draw() {
/*
if(channel.length>3) {
for (int i=3; i<channel.length; i++) {
ellipse(400,300, channel[i], channel[i]);
}
}*/
}
void serialEvent (Serial myPort) {
background(0);
String[] incomingValues = split(myPort.readString(), ',');
if (incomingValues.length>1) {
packetCount++;
println(incomingValues[1]);
// if ((incomingValues.length>1)&& (millis()-last>100))
if (incomingValues.length>1)
{
stroke(255);
int amplitude = 100-Integer.parseInt(incomingValues[1].trim());
// last=millis();
float y = 0;
float prevY = 0;
for (int i = 1; i < width; i++)
{
// amplitude= amplitude*millis();
y = sin(radians(i*2))*amplitude;
line(i-1, prevY+height/2, i, y+height/2);
prevY = y;
}
}
}
}
1