Recitation 8 Serial communication

Recitation 8 Serial Communication 

Step 1 Make an ellipse with potentiometers: 

Using the multiple values in class example, here are the changes I made: 

(Arduino)

void loop() {
int sensor1 = analogRead(A0);
int sensor2 = analogRead(A1);

int mappedValue1 = map(sensor1, 0, 1023, 0,255);
int mappedValue2 = map(sensor2, 0, 1023, 0,255);

Serial.print(mappedValue1);
Serial.print(“,”); 
Serial.print(mappedValue2);
Serial.println()

(Processing)

int NUM_OF_VALUES = 2;

background(0);
ellipse(sensorValues[0], sensorValues[1],50,50);

Step 2 Make a line etch-a-sketch: 

Still using the in class example of multiple values: 

(processing)

float xoldvalue;
float yoldvalue;

stroke(255);
line(xoldvalue, yoldvalue, sensorValues[0], sensorValues[1] );
xoldvalue = sensorValues[0];
yoldvalue = sensorValues[1];

Make an instrument 

I used the one value file to do this

(processing)

if (mousePressed && mouseY>250 ) {

}

(Arduino: 

if (valueFromProcessing == ‘H’) {
digitalWrite(ledPin, HIGH);
tone(ledPin, 2000);

} else if (valueFromProcessing == ‘L’) {
digitalWrite(ledPin, LOW);
tone(ledPin, 8000);
} else {
digitalWrite(ledPin, LOW);
noTone(ledPin);

}

Result: this made the sound of the buzzer, and when the mouse went above 250 (half) of the canvas, then the tone of the buzzer was higher pitched (8000). 

Leave a Reply