Facebook
From chiara_diana, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 143
  1. import processing.serial.*;
  2.  
  3. Serial myPort; // The serial port:
  4. int backValue = 255; // Declare variable 'backValue' and assign it the value 255
  5.  
  6. void setup() { //  The setup() function is run once, when the program starts. It's used to define initial enviroment properties.
  7.  size(640, 360);
  8.  
  9.  background(backValue);
  10.  printArray(Serial.list()); // List all the available serial ports:
  11.  myPort = new Serial(this, "COM5", 9600); // Open the port you are using at the rate you want:
  12. }
  13.  
  14. void draw() { //  Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called.
  15. }
  16.  
  17. void mousePressed() { //The mousePressed() function is called once after every time a mouse button is pressed.
  18.  if (backValue == 255) { //If the test evaluates to true, the statements enclosed within the block are executed
  19.    backValue = 10;
  20.    myPort.write(0); //low
  21.  } else { //It specifies a block of code to execute when the expression in if is false.
  22.    backValue = 255;
  23.    myPort.write(1); //high
  24.  }
  25.  background(backValue);
  26. }
  27.