Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Ruben Zilzer
Published © GPL3+

Paddle A Sketch (Tm)

Electronic "Etch a Sketch" to draw directly on the computer and save the screens.

BeginnerShowcase (no instructions)4 hours2,042
Paddle A Sketch (Tm)

Things used in this project

Hardware components

Rotary potentiometer (generic)
Rotary potentiometer (generic)
×2
tilt sensor sw-502d
×1
Arduino UNO
Arduino UNO
×1

Hand tools and fabrication machines

x-acto
I made the box from 3mm plywood and the knobs with soda caps

Story

Read more

Schematics

paddlea scketch

schematics

Code

Arduino part for the Paddle a sketch

Arduino
This parts reads the value of two potentiometers and the tilt sensor and send them to the serial output.
int x;
int y;
int pushButton = 2;//originally was a pushbutton but now is a tilt sensor

void setup()
{
  Serial.begin(9600);
  pinMode(2,INPUT);
}

void loop()
{
 int buttonState = digitalRead(pushButton);
  x = analogRead(A0);
  y = analogRead(A1);
  Serial.print(x);
  Serial.print(",");
  Serial.print(y);
  Serial.print(",");
  Serial.println(buttonState);
  delay(50);
}

Processing part for the paddle a scketch

Java
This is the Java part that reads the serial output from Arduino and draws in the screen.
// Etch-a-Sketch
// based on a sketch by Trevor Shannon

import processing.serial.*;

Serial port;
String serialInterface = "COM5";
int lastX = -1;
int lastY = -1;

void setup() {
  size(1024, 920);
  background(205);
  port = new Serial(this, serialInterface, 9600);  
}

void handleData(int x, int y) {
  if (lastX >= 0 && lastY >= 0) {
    line(x, y, lastX, lastY);
  }
  lastX = x;
  lastY = y;
}  

void draw() {
  readSerial();
}

void mouseClicked() {
  saveFrame(); 
 // added to save the drawing
}

void readSerial() {  
  int x; int y; int z;
  String s;
  while ((s = port.readStringUntil('\n')) != null) {
    String[] parts = s.substring(0, s.length()-2).split(",");
    if (parts.length == 3) {

      x = int(parts[0]);
      y = int(parts[1]);
      z = int(parts[2]);
      if (z==0) {
      background(205);//clears the screen when shaken
    }

      handleData(x, y);
    }
  }
}

Credits

Ruben Zilzer

Ruben Zilzer

6 projects • 7 followers
I'm a graphic designer (pre-computers era), a web programmer and digital media teacher support in Sapir College in Israel

Comments