week 11 exercise – Thais and Shaikha

Exercise 1

Make something that uses only one sensor  on arduino and makes the ellipse in processing move on the horizontal axis, in the middle of the screen, and nothing on arduino is controlled by processing
For this exercise we used the potentiometer to control the movement of the ellipse
Arduino

 

Exercise 1

Make something that uses only one sensor  on arduino and makes the ellipse in processing move on the horizontal axis, in the middle of the screen, and nothing on arduino is controlled by processing
For this exercise we used the potentiometer to control the movement of the ellipse
Arduino

 

 

Processing

 

 

Exercise 2

Make something that controls the LED brightness from processing.
For this exercise we used the x value of the position of the mouse to control the brightness of the LED.
Arduino
//Exercise 2

int ledPin = 5;

float brightness;

void setup() {
  Serial.begin(9600);
  Serial.println("0");
  pinMode(ledPin, OUTPUT);
}

void loop() {
  while (Serial.available()) {
    //get the brightness value from processing
    brightness = Serial.parseFloat();
    
    if (Serial.read() == '\n') {
    //turn on the LED with the given brightness
      analogWrite(ledPin, brightness);
      Serial.println(brightness);
    }
  }
}

 

Processing

 

//Exercise 2
import processing.serial.*;
Serial myPort;
int xPos = 0;
int yPos;

int brightness;

void setup() {
  size(960, 720);
  printArray(Serial.list());
  String portname=Serial.list()[3]; // "/dev/cu.usbmodem101"
  println(portname);
  myPort = new Serial(this, portname, 9600);
  myPort.clear();
  myPort.bufferUntil('\n');
}

void draw() {
  background(255);

  //map the mouseX position to the range of birghtness of the LED
  brightness = int(map(mouseX, 0, width, 0, 255));
  
  yPos = height/2;
  ellipse(mouseX, yPos, 30, 30);
}

void serialEvent(Serial myPort) {
  String s=myPort.readStringUntil('\n');
  s=trim(s);

  //write brightness so that Arduino can use it
  myPort.write(brightness+ "\n");
}

 

Exercise 3

Take the gravity wind example (https://github.com/aaronsherwood/introduction_interactive_media/blob/master/processingExamples/gravityExamples/gravityWind/gravityWind.pde) and make it so every time the ball bounces one led lights up and then turns off, and you can control the wind from one analog sensor.
The analog sensor we used was the potentiometer.
Arduino
int left = 0;
int right = 0;

int light1 = 0;
int LED1 = LOW;

void setup() {
  Serial.begin(9600);
  Serial.println("0,0");
  pinMode(2, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  while (Serial.available()) {
    //    right = Serial.parseInt();

    //get whether LED should be turned on from Processing
    light1 = Serial.parseInt();
    
    Serial.println(light1);

    if (Serial.read() == '\n')
    {
      
      if (light1 == 1)
      {
        LED1 = HIGH;
      }
      else
      {
        LED1 = LOW;
        
      }
      digitalWrite(5, LED1);

      //get the vvalues from the potentiometer
      int sensor = analogRead(A0);
      delay(1);
     
      //      delay(1);
      Serial.println(sensor);
      
      //      Serial.print(',');
      //      Serial.println(sensor2);
      
      //Serial.println(LED1);
    }
  }
}

 

Processing

 

Leave a Reply