Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Control Ellispe Diameter with values sent from Arduino.
- *
- * Using an Arduino and Potentiometer, contro the diameter of an ellipse
- * Recieve values using Serial I/O library
- */
- import processing.serial.*;// import serial library
- float diameter = 0.0; // the size of the ellipse
- float maxDiameter = 200.0;
- float minDiameter = 1.0;
- Serial myPort; // The serial port
- int dpi = 300;
- void setup() {
- size(600, 600);
- smooth();
- background(0);
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[0], 9600);
- }
- void draw() {
- rectMode(CENTER);
- pushMatrix();
- translate(mouseX, mouseY);
- rotate(radians(diameter));
- rect(0, 0, diameter, diameter);
- popMatrix();
- }
- /**
- * serialEvent
- *
- * This function access the values coming in from the serial port
- * It assigns the values to the diameter of the ellipse called, diameter
- * The diamter has a range of minDiamter to maxDiameter
- * These values are determined by the minDiameter and maxDiameter variables
- * If you alter them you can change the range of the diameter of the ellipse
- * For this to work, an Arduino must be sending one byte through the serial port
- */
- void serialEvent (Serial myPort) {
- // get the byte:
- int inByte = myPort.read();
- diameter = map(inByte, 0, 255, minDiameter, maxDiameter);
- // print it:
- println(inByte);
- }
- // This can be tested with using the keys if you are unable to access and Arduino and potentiometer
- // The UP key increases the speed and the DOWN key decreases the speed
- void keyPressed() {
- if (keyCode == UP) {
- diameter += 0.1;
- diameter = constrain(diameter, minDiameter, maxDiameter);
- }
- if (keyCode == DOWN) {
- diameter -= 0.1;
- diameter = constrain(diameter, minDiameter, maxDiameter);
- }
- println("adjusted diameter with keys to: " + diameter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement