This new media work is to challenge the preconceptions of the viewer through the use of mirror and electronics in an experiential setting.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You’ll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN 143 // this is the ‘minimum’ pulse length count (out of 4096)
#define SERVOMAX 400 // this is the ‘maximum’ pulse length count (out of 4096)
// our servo # counter
uint8_t servonum = 0;
uint8_t servonum1 = 1;
uint8_t servonum2 = 2;
uint8_t servonum3 = 3;
uint8_t servonum4 = 4;
uint8_t servonum5 = 5;
uint8_t servonum6 = 6;
uint8_t servonum7 = 7;
void setup() {
pinMode (2,OUTPUT);//attach pin 2 to vcc
pinMode (5,OUTPUT);//attach pin 5 to GND
// initialize serial communication:
Serial.begin(9600);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
}
void loop()
{
digitalWrite(2, HIGH);
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(3, OUTPUT);// attach pin 3 to Trig
digitalWrite(3, LOW);
delayMicroseconds(2);
digitalWrite(3, HIGH);
delayMicroseconds(5);
digitalWrite(3, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode (4, INPUT);//attach pin 4 to Echo
duration = pulseIn(4, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print(“in, “);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();
delay(100);
if (inches < 10 ) {
//Drive each servo one at a time
Serial.println(servonum, 0);
Serial.println(servonum1, 1);
Serial.println(servonum2, 2);
Serial.println(servonum3, 3);
Serial.println(servonum4, 4);
Serial.println(servonum5, 5);
Serial.println(servonum6, 6);
Serial.println(servonum7, 7);
pwm.setPWM(servonum, 0, SERVOMAX);
delay(60);
pwm.setPWM(servonum1, 1, SERVOMAX);
delay(60);
pwm.setPWM(servonum2, 2, SERVOMAX);
delay(60);
pwm.setPWM(servonum3, 3, SERVOMAX);
delay(60);
pwm.setPWM(servonum4, 4, SERVOMAX);
delay(60);
pwm.setPWM(servonum5, 5, SERVOMAX);
delay(60);
pwm.setPWM(servonum6, 6, SERVOMAX);
delay(60);
pwm.setPWM(servonum7, 7, SERVOMAX);
delay(60);
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen–) {
pwm.setPWM(servonum, 0, pulselen);
pwm.setPWM(servonum1, 1, pulselen);
pwm.setPWM(servonum2, 2, pulselen);
pwm.setPWM(servonum3, 3, pulselen);
pwm.setPWM(servonum4, 4, pulselen);
pwm.setPWM(servonum5, 5, pulselen);
pwm.setPWM(servonum6, 6, pulselen);
pwm.setPWM(servonum7, 7, pulselen);
}
}
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
long microsecondsToInches(long microseconds)
{
// According to Parallax’s datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}