Input Light / Output Screen

Light as Input on Arduino and an Output on the Screen

Here the photodiode receives input and acts as the external input device on Arduino, the activity
of which was monitored through the program running on processing through a serial port and the
output was generated on the screen using processing language.

Here a square keeps on alternating colours between black and white corresponding to the blinking of the LED.

Code for Arduino IDE

int vPin = 1;
int outputPin = 13;
int checkPin = 7;
int val = 0;

void setup() {
Serial.begin(9600);
pinMode(outputPin, OUTPUT);
pinMode(checkPin, OUTPUT);
}

int h = 1;
int l = 0;

void loop() {
val = analogRead(vPin);
digitalWrite(outputPin, HIGH);
if (Serial.available()) {
Serial.print(h);
}
delay(val);
digitalWrite(outputPin, LOW);
if (Serial.available()) {
Serial.print(l);
}
delay(val);
}

Code for Processing

import processing.serial.*;

Serial port;

void setup()
{
size(400,400);
background(255,255,0);
frameRate(10);
println(Serial.list());
port = new Serial(this, Serial.list()[2], 9600);
}

int val = 0;
int portval = 0;

void draw()
{
port.write('0');
portval = port.read();
println(portval);
if (portval == '1')
{
fill(255);
rect(100,100,200,200);
}

else if (portval == '0')
{
fill(0);
rect(100,100,200,200);
}
}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License