Posted on and Updated on

Intro to Physical Computing ⁄ Week 4 ⁄ Lab

Servo

Variable resistor (FSR) triggering servo rotation using the code given in the lab.

A display pedestal, activated via push-button. Behold — coffee.


 

Tone

Following the tone lab I created a noise instrument using two 8 ohm speakers, four buttons hooked up to analog pins, one button hooked up to digital, and three potentiometers.

Controls from top to bottom: volume, four notes (A2, C2, E2, G2), a fifth note or variable frequency controlled by the potentiometer just below it, and finally a delay effect.

The code for this setup (pitches.h file on this page):

#include "pitches.h"

const int threshold = 10;
const int speakerPin = 8;
const int noteDuration = 20;
 
int notes[] = { NOTE_A2, NOTE_C2, NOTE_E2, NOTE_G2 };

void setup() {}
 
void loop() {
  for (int thisSensor = 0; thisSensor < 4; thisSensor++) {    

  int sensorReading = analogRead(thisSensor);
   
  if (sensorReading > threshold) {
        tone(speakerPin, notes[thisSensor], 20);
    }
  }

  int sensorReading2 = map(analogRead(4), 662, 1023, 50, 2000);
  if(sensorReading2 < 0){
    sensorReading2 = 0;
  }
  if(digitalRead(3) == HIGH){
    tone(speakerPin, sensorReading2, 20);
  }

  int sensorReading3 = map(analogRead(5), 662, 1023, 0, 100);
  if(sensorReading3 < 0){
    sensorReading3 = 0;
  }
  delay(sensorReading3);
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *