Prototyping Class
December 15, 2021
Arduino to Processing • Final Project
As soon as I was able to connect my Processing app to the Arduino project, I created a visualization that looks like a moving cloud in the midnight that produces lightning.
import processing.serial.*;
Serial arduinoConnection;
int sensor = 0;
int x = 0;
int xPos=0;
int xDir=1;
boolean stop = true;
void setup() {
printArray( arduinoConnection.list() );
println( arduinoConnection.list() );
size (1200, 600);
arduinoConnection = new Serial(this, Serial.list()[2], 9600);
}
void draw() {
// set the sky color
background(#354270);
// set the cloud color & object position
fill(255);
drawCloud(xPos, 200, 200);
if(stop){
// set the cloud object movement
xPos=xPos+xDir;
if( xPos >= width ) {
// we've run off the edge
background(#354270);
xPos = 0;
}
}
// create a running line graph
// x = time, y = sensor value
float y = map( sensor, height/2, height, height/2, height );
// float bright = map( sensor, 0, 1, 255, 0 );
float bright = map( sensor, 0, 1, 255, 0 );
fill( #FFFFFF );
rect( x,(height/2)+y,8,8*y );
x++;
if( x >= width ) { // we've run off the edge
background(#354270);
x = 0;
}
}
// set the cloud object based on 3 ellipses
void drawCloud(float cloudX, float cloudY, float flakeSize) {
float flakeDistance = flakeSize / 3;
fill(255);
noStroke();
// lower-left flake
ellipse(cloudX - flakeDistance, cloudY + flakeDistance*0.5, 120, 120);
// lower-right flake
ellipse(cloudX + flakeDistance, cloudY + flakeDistance*0.3, 150, 150);
// center flake
fill(255);
ellipse(cloudX, cloudY, flakeSize, flakeSize);
}In result I have got this nice cloud mthat makes lightning.
I Hope, you liked my Final project. Please, leave any comments!