const int LED_ROJO = A4; // declaring red led in A4 pin const int LED_VERDE = A2; // declaring green led on A2 pin const int LED_AZUL = A3; // declaring blue led on A3 pin void setup() { // Initializing leds pinMode(LED_ROJO, OUTPUT); pinMode(LED_VERDE, OUTPUT); pinMode(LED_AZUL, OUTPUT); } void loop() { analogWrite(LED_ROJO, 0); // Red led ON delay(1000); analogWrite(LED_ROJO, 255); // Red led OFF analogWrite(LED_VERDE, 0); // Green led ON delay(1000); analogWrite(LED_VERDE, 255); // Green led OFF analogWrite(LED_AZUL, 0); // Blue led ON delay(1000); analogWrite(LED_AZUL, 255); // Blue led OFF } //starts loop again
import processing.serial.*; PImage img; Serial myPort; void setup() { //set these to the size of the image size(512,512); //this is the name of your image file saved in the data folder in your //processing folder see processing.org for help img = loadImage("RGBR.jpg"); //the [0] may be [another number] on your computer myPort = new Serial(this, Serial.list()[0], 9600); } void draw() { background(0); image(img,0,0); img.loadPixels(); } void mousePressed() { myPort.write("CL"); myPort.write(int(red(img.pixels[mouseX+mouseY*img.width]))); myPort.write(int(green(img.pixels[mouseX+mouseY*img.width]))); myPort.write(int(blue(img.pixels[mouseX+mouseY*img.width]))); }
// Output int redPin = A4; // Red LED, connected to digital pin 9 int greenPin = A2; // Green LED, connected to digital pin 10 int bluePin = A3; // Blue LED, connected to digital pin 11 long int inByte; int wait = 10; //10ms void setup() { pinMode(redPin, INPUT_PULLUP); // sets the pins as output pinMode(greenPin, INPUT_PULLUP); pinMode(bluePin, INPUT_PULLUP); Serial.begin(9600); } void outputColour(int red, int green, int blue) { analogWrite(redPin, red); analogWrite(bluePin, blue); analogWrite(greenPin, green); } int* getColour() { int* colour; int i; i = 0; //for some reason it only works if we put a dud value between the C and // the R value while (i < 4) { if (Serial.available() > 0) { colour[i] = Serial.read(); i++; } } return colour; } // Main program void loop() { if (Serial.available() > 0) { // get incoming byte: inByte = Serial.read(); if (inByte == 'C') { int* one; one = getColour(); //1 2 3 not 0 1 2 due to the dud value outputColour(one[1],one[2],one[3]); } } delay(wait); }
// Read data from the serial port and change the color of a rectangle // when a switch connected to the board is pressed and released import processing.serial.*; Serial port; // Create object from Serial class int val; // Data received from the serial port void setup() { size(200, 200); frameRate(10); // Open the port that the board is connected to and use the same speed (9600 bps) port = new Serial(this, Serial.list()[0], 9600); } void draw() { if (0 < port.available()) { // If data is available, val = port.read(); // read it and store it in val } background(255); // Set background to white if (val == 0) { // If the serial value is 0, fill(0); // set fill to black } else { // If the serial value is not 0, fill(204); // set fill to light gray } rect(50, 50, 100, 100); }
// Code for sensing a switch status and writing the value to the serial port int switchPin = 3; // Switch connected to pin 3 void setup() { pinMode(switchPin, INPUT_PULLUP); // Set pin 0 as an input Serial.begin(9600); // Start serial communication at 9600 bps } void loop() { if (digitalRead(switchPin) == LOW) { // If switch is ON, Serial.write(1); // send 1 to Processing } else { // If the switch is not ON, Serial.write(0); // send 0 to Processing } delay(100); // Wait 100 milliseconds }
import processing.serial.*; Serial port; // Create object from Serial class int val; // Data received from the serial port void setup() { size(800, 800); frameRate(10); // Open the port that the board is connected to and use the same speed (9600 bps) port = new Serial(this, Serial.list()[0], 9600); } void draw() { if (0 < port.available()) { // If data is available, val = port.read(); // read it and store it in val } background(255); // Set background to white if (val == 0) { // If the serial value is 0, fill(0); // set fill to black } else { // If the serial value is not 0, fill(204); // set fill to light gray } triangle(288, 18, 451, 460, 488, 460); //triangle formation triangle (150, 150, 451, 460, 488, 460); //triangle formation arc(479, 300, 280, 280, PI, TWO_PI); //arc formation quad(189, 18, 216, 18, 216, 360, 144, 360); //quadrilateral formation }
int switchPin = 3; // Switch connected to pin 3 void setup() { pinMode(switchPin, INPUT_PULLUP); // Set pin 0 as an input Serial.begin(9600); // Start serial communication at 9600 bps } void loop() { if (digitalRead(switchPin) == LOW) { // If switch is ON, Serial.write(1); // send 1 to Processing } else { // If the switch is not ON, Serial.write(0); // send 0 to Processing } delay(100); // Wait 100 milliseconds }