Interface and Application Programming |
Author's Note: I'm back!!This assignment is of development in Processing,so that this assignment consists of: --Why use processing? This will reinforce my learning Arduino Programming in Processing
/**
* Phototransistor Input to Circle * * Read data from the serial port and changes the fill and stroke color of a circle * relative to the values recieved from the sensor. * Circle fill and stroke are random, unless a sensor value below 200 is recived. */ //import serial library import processing.serial.*; Serial serialPort; // Create object from Serial class int diameter= 500; // initial diameter of the circle void setup() { size(500, 500); stroke(255); smooth(); // I know that the first port in the serial list on my mac // is always my FTDI adaptor, so I open Serial.list()[0]. // On Windows machines, this generally opens COM1. // Open whatever port is the one you're using. println(Serial.list()); serialPort = new Serial(this, Serial.list()[0], 9600); } void draw() { //filter out the 1,2,3,4 framing code numbers while (serialPort.available () > 4) { int lightIn = serialPort.read(); //if the sensor value is greater than 200 //(you may need to tweak this number to get the code to respond to your board) if (lightIn > 200) { //print in the sensor values to the console println(lightIn); //set the variable diameter to the sensor value diameter = lightIn; //use the sensor value to draw an ellipse ellipse(random(500), random(500), diameter, diameter); rect(random(500), random(500), diameter, diameter); //redraw the screen redraw(); } } //EXPERIMENT WITH THE VISUALIZATION BELOW //if the sensor values are less that 200, the elipse with random stroke and fill colors stroke((int)random(255), (int)random(255), (int)random(255)); fill((int)random(255), (int)random(255), (int)random(255)); } The final result is the following image an video: |