Electronic Etch a Sketch
in
Integration and Hardware
•
2 years ago
Ive been making a Digital Etch a Sketch and wanted a pulsating colour background which goes though the spectrum. I have achieved the background effect but now the lines from the etch a sketch dont stay on the page. Any idea on a fix?
- //importing
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int coordX;
int coordY;
int smoothcoordX;
int smoothcoordY;
int prevX;
int prevY;
int xPin= 0;
int yPin= 1;
int firstrun;
float h = 1;
void setup() {
//println(h);
arduino = new Arduino(this, Arduino.list()[3], 57600);
colorMode(HSB);
size(1280,720);
smoothcoordX= arduino.analogRead(xPin);
smoothcoordY= arduino.analogRead(yPin);
}
void draw(){
if (h >= 255)
{
h = 1;
};
h = h + 0.05;
background(h,255,255);
prevX=smoothcoordX;
prevY=smoothcoordY;
coordX= arduino.analogRead(xPin);
coordY= arduino.analogRead(yPin);
smoothcoordX = prevX + coordX;
smoothcoordY = prevY + coordY;
smoothcoordX = smoothcoordX / 2;
smoothcoordY = smoothcoordY / 2;
drawLine();
}
void drawLine() {
strokeWeight(3);
stroke(20,0,30);
line(map(prevX, 0, 1023, 10, 1270),
map(prevY, 0, 1023, 10 , 710),
map(smoothcoordX, 0, 1023, 10, 1270),
map(smoothcoordY, 0, 1023, 10, 710));
}
1