Digital Electronics Lab 10

Video:

Processing Code:

import processing.serial.*;

Serial teensySerial;

int inputVal=0;
int inputVal2=0;
int inputVal3 = 0;
int inputVal4=0;
int inputVal5=0;
int circleSize=0;
int circleX=0;
int circleSpeed =0;
int circleY=0;

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

  //printArray(Serial.list());
  String usbPortName = Serial.list()[12];
  print(usbPortName);
  teensySerial = new Serial(this, usbPortName, 9600);
}

void draw() {

  if (teensySerial.available()>=6) {
    inputVal = teensySerial.read();
    if (inputVal == 0) {
      inputVal=teensySerial.read();
      inputVal2=teensySerial.read();
      inputVal3=teensySerial.read();
      inputVal4=teensySerial.read();
      inputVal5=teensySerial.read();
    
    }
  }
  background(inputVal4, 0, inputVal5);
  fill(0, 0, inputVal);
  circleSize= (int)map(inputVal2, 1, 255, 0, 500);
  circleSpeed=(int)map(inputVal3, 1, 255, 1, 50);
  circleX+=circleSpeed;
  if (circleX>500) {
    circleX=0;
  }
  circle(circleX, 250, circleSize);
 
}

Arduino Code:

int potPin = A14;
int potVal = 0;
int mappedPotVal = 0;

int potPin2 = A15;
int potVal2 = 0;
int mappedPotVal2 = 0;

int potPin3= A16;
int potVal3 = 0;
int mappedPotVal3 = 0;

int potPin4=A17;
int potVal4 = 0;
int mappedPotVal4 = 0;

int potPin5= A13;
int potVal5 = 0;
int mappedPotVal5 = 0;

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

void loop() {

  Serial.write(0);
  potVal = analogRead(potPin);
  mappedPotVal = map(potVal, 0, 1023, 1, 255);
  Serial.write(mappedPotVal);

  potVal2 = analogRead(potPin2);
  mappedPotVal2 = map(potVal2, 0, 1023, 1, 255);
  Serial.write(mappedPotVal2);

  potVal3 = analogRead(potPin3);
  mappedPotVal3 = map(potVal3, 0, 1023, 1, 255);
  Serial.write(mappedPotVal3);

  potVal4 = analogRead(potPin4);
  mappedPotVal4 = map(potVal4, 0, 1023, 1, 255);
  Serial.write(mappedPotVal4);

  potVal5 = analogRead(potPin5);
  mappedPotVal5 = map(potVal5, 0, 1023, 1, 255);
  Serial.write(mappedPotVal5);
  delay(50);
}


Leave a comment

Design a site like this with WordPress.com
Get started