Reflect and Processing

The board used serial protocol to connect the Computer.
I use a software called Processing,and this is my processing code.
Processing
1 | import processing.serial.*; Serial myPort; int lf = 10; void setup(){ size(300,300); //fill(0,255,0); //ellipse(100,100,100,100); //myPort = new Serial(this,"/dev/cu.usbmodem1421",9600); myPort = new Serial(this,"/dev/tty.usbserial",9600); } void draw(){ while(myPort.available() > 0){ String str = myPort.readStringUntil(lf); //println(str); if(str!=null){ int value = Integer.parseInt(trim(str)); int nValue = (value-200)*4; println(nValue); background(nValue); } } } |
At dark
If the board is in dark,the interface will be white.
At bright light
When the board on front of light,the interface will be dark.
Arduino
1 | #include "SoftwareSerial.h" const int analogInPin = A2; // Analog input pin that the potentiometer is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) const int Rx = 1; // this is physical pin 7 const int Tx = 2; // this is physical pin 6 SoftwareSerial mySerial(Rx, Tx); void setup() { // pinMode(3, OUTPUT); pinMode(Rx, INPUT); pinMode(Tx, OUTPUT); mySerial.begin(9600); // send serial data at 9600 bits/sec } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); mySerial.println(outputValue); delay(100); } |
Serial Output
Test Arduino and Processing together

File download

This work is licensed under a Creative Commons Attribution 4.0 International License.