Digital Lab 09

This is the Arduino code:

int potValArray[5] = {0, 0, 0, 0, 0};
int potPinArray[5] = {A18, A17, A16, A15, A14};
int totalPots = 5;

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.write(0);
  //Serial.println(0);
  for(int i = 0; i < totalPots; i++){
    potValArray[i] = analogRead(potPinArray[i]);
    potValArray[i] = map(potValArray[i], 0, 1023, 1, 255);
    Serial.write(potValArray[i]);
    delay(50);
    //Serial.println(potValArray[i]);
  }

  
}

This is the Processing code:

import processing.serial.*;

Serial teensySerial;
int inputVal = 0;
int inputVal2 = 0;
int inputVal3 = 0;
int inputVal4 = 0;
int inputVal5 = 0;
int inputVal6 = 0;

int ellipseX = 0;
int ellipseY = 0;
int ellipseWidth = 0;
int ellipseHeight = 0;

void setup(){
  frameRate(30);
  size(500, 500);

  String usbPortName = Serial.list()[7];
  teensySerial = new Serial(this, usbPortName, 9600);
}

void draw(){
  if(teensySerial.available() > 6) {
    inputVal = teensySerial.read();
    if(inputVal == 0){
       inputVal2 = teensySerial.read();
       inputVal3 = teensySerial.read();
       inputVal4 = teensySerial.read();
       inputVal5 = teensySerial.read();
       inputVal6 = teensySerial.read();
    }
  }
  
  background(inputVal2, inputVal3, inputVal4);
  
  fill(inputVal5, inputVal6, inputVal2);
  
  ellipseX = (int)map(inputVal2, 1, 255, 0, 500);
  ellipseY = (int)map(inputVal3, 1, 255, 0, 500);
  ellipseWidth = (int)map(inputVal4, 1, 255, 0, 500);
  ellipseHeight = (int)map(inputVal5, 1, 255, 0, 500);
  ellipse(ellipseX, ellipseY, ellipseWidth, ellipseHeight);
  
}

Leave a comment

Design a site like this with WordPress.com
Get started