Write an application that interfaces with an input &/or output device that you made, comparing as many tool options as possible
In this section, we use Processing SOftware and Arduino to display the sensor values
Processing connects to Arduino via Serial, the Arduino reads the sensor values and sends it back to prossesing.
============================================================ Processing Version: 2.2.1 Project: Display Sensor data on computer screen Author: ScottC Created: 25th June 2011 Description: This Processing sketch will allow you to display sensor data received from the Arduino via the serial COM port (or USB cable). =============================================================== */ import processing.serial.*; Serial myPort; String sensorReading=""; PFont font; void setup() { size(400,200); myPort = new Serial(this, "COM5", 9600); myPort.bufferUntil('\n'); font = createFont(PFont.list()[2],32); textFont(font); } void draw() { //The serialEvent controls the display } void serialEvent (Serial myPort){ sensorReading = myPort.readStringUntil('\n'); if(sensorReading != null){ sensorReading=trim(sensorReading); } writeText("Sensor Reading: " + sensorReading); } void writeText(String textToWrite){ background(255); fill(0); text(textToWrite, width/20, height/2); }
Now that my boards did not have serial IC interface, I used Arduino and programmed as below
int photoRPin = 0; int minLight; //Used to calibrate the readings int maxLight; //Used to calibrate the readings int lightLevel; int adjustedLightLevel; void setup() { Serial.begin(9600); //Setup the starting light level limits lightLevel=analogRead(photoRPin); minLight=lightLevel-20; maxLight=lightLevel; } void loop(){ //auto-adjust the minimum and maximum limits in real time lightLevel=analogRead(photoRPin); if(minLight>lightLevel){ minLight=lightLevel; } if(maxLight maxLight=lightLevel; } //Adjust the light level to produce a result between 0 and 100. adjustedLightLevel = map(lightLevel, minLight, maxLight, 0, 100); //Send the adjusted Light level result to Serial port (processing) Serial.println(adjustedLightLevel); //slow down the transmission for effective Serial communication. delay(50); }