Midterm

Arduino:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char val; // variable that will be sent between the programs processing and arduino
void setup() {
Serial.begin(9600); // starts serial port

lcd.print(” -_- “); // starting face
}
void loop() {
if (Serial.available())
{ // looking for data
val = Serial.read(); // will take it and put it in the the variable ‘val’
}
if (val == ‘1’)
{ // If 1 was received
lcd.print(” 🙂 “);

}

if (val == ‘2’)
{ // If 2 was received
lcd.print(” 😦 “);

}

if (val == ‘3’)
{ // If 3 was received
lcd.print(” -_- “);

}}

Processing:

import processing.serial.*;// importing serial port

Serial myPort; // Create object from Serial class and talk to arduino

//images in ui
PImage img;
PImage img2;
PImage img3;
void setup()
{

size(500,500);
background(33, 212, 146);
String portName = Serial.list()[0]; //array for serial port
myPort = new Serial(this, “COM3”, 9600);
img = loadImage(“1.png”);
img2 = loadImage(“2.png”);
img3 = loadImage(“3.png”);
}
void draw() {

// smiley button
if (mousePressed) {
if (mouseX>156 && mouseX <156+54 && mouseY>53 && mouseY <156+54) {
println(“The mouse is pressed for smile”);
background(random(255));
fill(#ffa000);

//if we clicked in the window
myPort.write(‘1’); //send a 1
println(“1”);
}
}

// sad button
if (mousePressed) {
if (mouseX>156 && mouseX <156+214 && mouseY>214 && mouseY <156+214) {
println(“The mouse is pressed for smile”);
background(random(255));
fill(33, 212, 146);

myPort.write(‘2’); //send a 1
println(“2”);
}
} else

{ myPort.write(‘0’);
}

// passive button
if (mousePressed) {
if (mouseX>156 && mouseX <156+374 && mouseY>374 && mouseY <156+374) {
println(“The mouse is pressed for smile”);
background(random(255));
fill(33, 212, 146);

//if we clicked in the window
myPort.write(‘3’); //send a 1
println(“3”);
} else

{ myPort.write(‘0’);
}
}

image(img, 156, 54);
image(img2, 156, 214);
image(img3, 156, 374);
}

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s