WEEK 14

ASSIGNMENT

 

1. Making and application to see the visual in the computer with any Analog Sensor

 

 

PROCESSING

For interface and application programming, I decided to use Processing to generate a graphic from output generated to on and off the RGB led lights

on the twinkle tricks board I created

 

To start I downloaded Processing

After downloading Processing I got this on the screen

 

I decided to write a code which will create a rectangular button on the interface which will turn ON when the curse was in the rectangle else turn Off

 

 

import processing.serial.*;

Serial port;

void setup() {

port = new Serial(this, "/dev/cu.usbmodem1421", 9600); //define the port at which the Arduino is connected

size(300, 300);

background(255);

}

void draw() {

background(255);

rect(100, 100, 50, 50);

if ( dist( mouseX, mouseY, 100, 100 ) < 25 ) {

port.write('1');

fill( 0, 255, 0 );

text("ON", 10, 30);

} else {

port.write('0');

fill( 255, 0, 0 );

text("OFF", 10, 30);

}

delay(100);

}

 

 

Ardiuno Code

 

int state;

void setup() {

pinMode(13, OUTPUT);

Serial.begin(9600);

}

void loop() {

if (Serial.available() > 0) {

state = Serial.read();

if (state == '1') {

digitalWrite(13, HIGH);

}

if (state == '0') {

digitalWrite(13, LOW);

}

}

delay(50);

}

Site created by Lavina Utamani using Adobe Muse | fabacademy 2017