/*
* Processing code for WordDuo Project. All images are being used for
* educational purposes we do not own these images.
*/
import processing.sound.*;
import cc.arduino.*;
import org.firmata.*;
import processing.serial.*;
Arduino arduino;
int ss3 = 0;
int ss4 = 0;
int ss5 = 0;
int ss11 = 0;
int ss12 = 0;
int ss13 = 0;
int on = 0;
PFont f;
int fr = 10;
SoundFile file;
PImage speech;//speech bubble
Animation dog, character, background, cat, rainA, rainB, rainC, pizza;
void setup(){
println(Arduino.list());
arduino= new Arduino(this,Arduino.list()[2],57600);
arduino.pinMode(2,Arduino.INPUT); // declares pin 2 as an INPUT
arduino.pinMode(3,Arduino.INPUT); // declares pin 5 as an OUTPUT
arduino.pinMode(4,Arduino.INPUT);
arduino.pinMode(5,Arduino.INPUT);
arduino.pinMode(10,Arduino.INPUT);
arduino.pinMode(11,Arduino.INPUT);
arduino.pinMode(12,Arduino.INPUT);
arduino.pinMode(13,Arduino.INPUT);
fullScreen();
background(0);
//Font
f = createFont("Arial Black",16,true);
//Background
background = new Animation("background",12);
//Animations
character = new Animation("character", 6);
dog = new Animation("dog", 4);
cat = new Animation("cat", 9);
rainA = new Animation("rain", 2);
rainB = new Animation("rain", 2);
rainC = new Animation("rain", 2);
pizza = new Animation("pizza",2);
//Image
speech = loadImage("Speech.png");
speech.resize(200,200);
//Background music
file = new SoundFile(this, "music1.wav");
file.loop();
}
void draw(){
ss3 = arduino.digitalRead(3);
ss4 = arduino.digitalRead(4);
ss5 = arduino.digitalRead(5);
ss11 = arduino.digitalRead(11);
ss12 = arduino.digitalRead(12);
ss13 = arduino.digitalRead(13);
on = Arduino.HIGH;
frameRate(fr);
background.display(0,0);
character.display(width/4,(height/3)*2);
if ( ss5 == on && ss13 == on){//CAT
cat.display(width/6,height/6);
textFont(f,60);
fill(255);
textAlign(CENTER);
text("el gato = cat", width/2, height/5);
image(speech, width/2, height/3);
}
else if (ss4 == on && ss12 == on){//EAT
pizza.display((width/2) + 10, (height/5)*4);
textFont(f,60);
fill(255);
textAlign(CENTER);
text("comer = eat", width/2, height/5);
image(speech, width/2, height/3);
}
else if ( ss3 == on && ss11 == on){//RAIN
rainA.display(width/3,height/4);
rainB.display(width/12, height/7);
rainC.display((width/3)*2, height/5);
textFont(f,60);
fill(255);
textAlign(CENTER);
text("la lluvia = rain", width/2, height/5);
image(speech, width/2, height/3);
}
else if ( ss3 == on && ss11 == on && ss4 == on && ss12 == on){//RUN
fr = 20;//change frame rate
//text
textFont(f,60);
fill(255);
textAlign(CENTER);
text("correr = run", width/2, height/5);
//match speech
image(speech, width/2, height/3);
}
else if ( ss4 == on && ss12 == on && ss5 == on && ss13 == on ){//DOG
//dog animation
dog.display(width/6, height/2);
//text
textFont(f,60);
fill(255);
textAlign(CENTER);
text("el perro = dog", width/2, height/5);
//match speech
image(speech, width/2, height/3);
}
else { //if no match at all
//text
fr = 10;
textFont(f,60);
fill(255);
textAlign(CENTER);
text("NO MATCH, TRY AGAIN", width/2, height/2);
}
}
/*
* Class for animating a sequence of GIFs taken
* from an example on Processing.org called
* Animated Sprite (Shifty + Teddy) by James Paterson.
* https://processing.org/examples/animatedsprite.html
*/
class Animation {
PImage[] images;
int imageCount;
int frame;
Animation(String imagePrefix, int count) {
imageCount = count;
images = new PImage[imageCount];
for (int i = 0; i < imageCount; i++) {
// Use nf() to number format 'i' into four digits
String filename = imagePrefix + nf(i, 4) + ".gif";
if ( imagePrefix == "background"){
images[i] = loadImage(filename);
images[i].resize(width,height);
}
else if (imagePrefix == "pizza"){
images[i] = loadImage(filename);
images[i].resize(100,100);
}
else {
images[i] = loadImage(filename);
}
}
}
void display(float xpos, float ypos) {
frame = (frame+1) % imageCount;
image(images[frame], xpos, ypos);
}
int getWidth() {
return images[0].width;
}
}
* Processing code for WordDuo Project. All images are being used for
* educational purposes we do not own these images.
*/
import processing.sound.*;
import cc.arduino.*;
import org.firmata.*;
import processing.serial.*;
Arduino arduino;
int ss3 = 0;
int ss4 = 0;
int ss5 = 0;
int ss11 = 0;
int ss12 = 0;
int ss13 = 0;
int on = 0;
PFont f;
int fr = 10;
SoundFile file;
PImage speech;//speech bubble
Animation dog, character, background, cat, rainA, rainB, rainC, pizza;
void setup(){
println(Arduino.list());
arduino= new Arduino(this,Arduino.list()[2],57600);
arduino.pinMode(2,Arduino.INPUT); // declares pin 2 as an INPUT
arduino.pinMode(3,Arduino.INPUT); // declares pin 5 as an OUTPUT
arduino.pinMode(4,Arduino.INPUT);
arduino.pinMode(5,Arduino.INPUT);
arduino.pinMode(10,Arduino.INPUT);
arduino.pinMode(11,Arduino.INPUT);
arduino.pinMode(12,Arduino.INPUT);
arduino.pinMode(13,Arduino.INPUT);
fullScreen();
background(0);
//Font
f = createFont("Arial Black",16,true);
//Background
background = new Animation("background",12);
//Animations
character = new Animation("character", 6);
dog = new Animation("dog", 4);
cat = new Animation("cat", 9);
rainA = new Animation("rain", 2);
rainB = new Animation("rain", 2);
rainC = new Animation("rain", 2);
pizza = new Animation("pizza",2);
//Image
speech = loadImage("Speech.png");
speech.resize(200,200);
//Background music
file = new SoundFile(this, "music1.wav");
file.loop();
}
void draw(){
ss3 = arduino.digitalRead(3);
ss4 = arduino.digitalRead(4);
ss5 = arduino.digitalRead(5);
ss11 = arduino.digitalRead(11);
ss12 = arduino.digitalRead(12);
ss13 = arduino.digitalRead(13);
on = Arduino.HIGH;
frameRate(fr);
background.display(0,0);
character.display(width/4,(height/3)*2);
if ( ss5 == on && ss13 == on){//CAT
cat.display(width/6,height/6);
textFont(f,60);
fill(255);
textAlign(CENTER);
text("el gato = cat", width/2, height/5);
image(speech, width/2, height/3);
}
else if (ss4 == on && ss12 == on){//EAT
pizza.display((width/2) + 10, (height/5)*4);
textFont(f,60);
fill(255);
textAlign(CENTER);
text("comer = eat", width/2, height/5);
image(speech, width/2, height/3);
}
else if ( ss3 == on && ss11 == on){//RAIN
rainA.display(width/3,height/4);
rainB.display(width/12, height/7);
rainC.display((width/3)*2, height/5);
textFont(f,60);
fill(255);
textAlign(CENTER);
text("la lluvia = rain", width/2, height/5);
image(speech, width/2, height/3);
}
else if ( ss3 == on && ss11 == on && ss4 == on && ss12 == on){//RUN
fr = 20;//change frame rate
//text
textFont(f,60);
fill(255);
textAlign(CENTER);
text("correr = run", width/2, height/5);
//match speech
image(speech, width/2, height/3);
}
else if ( ss4 == on && ss12 == on && ss5 == on && ss13 == on ){//DOG
//dog animation
dog.display(width/6, height/2);
//text
textFont(f,60);
fill(255);
textAlign(CENTER);
text("el perro = dog", width/2, height/5);
//match speech
image(speech, width/2, height/3);
}
else { //if no match at all
//text
fr = 10;
textFont(f,60);
fill(255);
textAlign(CENTER);
text("NO MATCH, TRY AGAIN", width/2, height/2);
}
}
/*
* Class for animating a sequence of GIFs taken
* from an example on Processing.org called
* Animated Sprite (Shifty + Teddy) by James Paterson.
* https://processing.org/examples/animatedsprite.html
*/
class Animation {
PImage[] images;
int imageCount;
int frame;
Animation(String imagePrefix, int count) {
imageCount = count;
images = new PImage[imageCount];
for (int i = 0; i < imageCount; i++) {
// Use nf() to number format 'i' into four digits
String filename = imagePrefix + nf(i, 4) + ".gif";
if ( imagePrefix == "background"){
images[i] = loadImage(filename);
images[i].resize(width,height);
}
else if (imagePrefix == "pizza"){
images[i] = loadImage(filename);
images[i].resize(100,100);
}
else {
images[i] = loadImage(filename);
}
}
}
void display(float xpos, float ypos) {
frame = (frame+1) % imageCount;
image(images[frame], xpos, ypos);
}
int getWidth() {
return images[0].width;
}
}