Back to Parent

import processing.serial.*;

Serial myPort;  // The serial port
PImage image1;
PImage image2;
PImage image3;
PImage image4;
PImage image5;
char currentState;
void setup() {
  // List all the available serial ports
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[2], 115200);
  size(2736, 1824);
  background(0,0,0);
  image1 = loadImage("raspberriesyogurt.jpg");
  image2 = loadImage("banana.jpg");
  image3 = loadImage("almonds.jpg");
  image4 = loadImage("chocochipcookies60op.jpg");
  
}

void draw() {
  
  while (myPort.available() > 0) {
    int inByte = myPort.read();
    currentState = char(inByte);
    
    if (currentState == 'd') {
      background(0,0,0);
      image(image1, 0, 0);
    }
    else if (currentState == 's') {
      background(0,0,0);
      image(image2, 0, 0);
    }
    else if (currentState == 'w') {
      background(0,0,0);
      image(image3, 0, 0);
    }
    else if (currentState == 'a') {
      background(0,0,0);
      image(image4, 0, 0);
    }

  }
 
  
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0