Herewith is the computer software code named “Robot_hacks_Nov_2013”:
/* Desktop art sculpture by Team Tree Trunk, November 2013
(Rick Hill, Janeil Hill and Jennifer Nye)
Created in conjunction with the Robot Hacks event sponsored by
MAKE magazine and GE, 3-20 November 2013.
This project was inspired by the work of Erin Kennedy, aka RobotGrrl.
Once upon a time, there were five photosensitive cells that wanted
to play together.
They were gathered inside a dark rectangular box when they felt
a commotion.
It was a two-eyed entity that called itself an ultrasonic sensor,
telling the five photosensitive cells that ultrasonic sensors are
like the bat or other creature that uses echolocation to describe
its environment.
The six of them looked up and saw the big shadow and shape of
a giant that had lifted the lid of their box, exposing them to light,
showing them a world they had never seen before, full of odd
shapes and more entities just like themselves.
The giant removed them from the box and attached their legs into
holes that connected to rows of entities already in place, with
names like resistor, wire, LED and a complicated entity called
the Arduino.
The giant then played with them and gave them power.
They were more alive than ever before!
Excitedly, they joined with the wires, resistors, LEDs and Arduino
to move one-armed objects called servos.
Eventually, they left the rows of holes and were glued together
with metal to form a new network of connections inside a
cylindrical box.
The giant told them they were going to become a desktop art sculpture,
a Cubist version of a robot, dissected into its separate parts and put
on display like a Damien Hirst cadaver.
He walked them through a strange language, based on the idea of logic,
that made them more than the sum of their parts…
Five LDRs/photocells and one ultrasonic sensor are pointed outward
in the circular side wall of a hat box.
Each photocell controls the movement of a small analog servo
attached to the lid of the hat box.
The ultrasonic sensor controls the movement of large analog servo
attached to the lid of the hat box, which in turn is connected to
a set of pulleys.
If the distance from an object to the ultrasonic sensor is less than 5,
then all of the servos are returned to their original “zero” position;
otherwise they rotate based on readings from the photocells and ultrasonic sensor.
*/
int photocellPin0 = 0; // the photocell is connected to a0
int photocellPin1 = 1; // the photocell is connected to a1
int photocellPin2 = 2; // the photocell is connected to a2
int photocellPin3 = 3; // the photocell is connected to a3
int photocellPin4 = 4; // the photocell is connected to a4
int photocellReading; // the analog reading from the sensor
int yourDistance; // the analog reading from the ultrasonic sensor
int servoPosition; // connect servos to pins D3, D5, D6, D9, D10 and D11
#include <Servo.h>
Servo myservo0; // create servo object to control a servo on D3
Servo myservo1; // create servo object to control a servo on D5
Servo myservo2; // create servo object to control a servo on D6
Servo myservo3; // create servo object to control a servo on D9
Servo myservo4; // create servo object to control a servo on D10
Servo myservo5; // create servo object to control a servo on D11
const int pingPin = 2;
const int closeD = 10; // cm; maximum closest distance – 0 to 10 cm range
const int midD = 20; // cm; maximum hand distance – 10 to 20 cm range
const int farD = 30; // cm; maximum farthest distance – 20 to 30 cm range
int pos = 0; // variable to store the servo position */
void setup(void) {
myservo0.attach(3); // attaches the servo 1 on pin 3 to the servo object
myservo1.attach(5); // attaches the servo 1 on pin 5 to the servo object
myservo2.attach(6); // attaches the servo 1 on pin 6 to the servo object
myservo3.attach(9); // attaches the servo 1 on pin 9 to the servo object
myservo4.attach(10); // attaches the servo 1 on pin 10 to the servo object
myservo5.attach(11); // attaches the servo 1 on pin 10 to the servo object
// We’ll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
yourDistance = getDistance(pingPin); // cm
yourDistance = constrain(yourDistance, 0, 50);
servoPosition = map(yourDistance, 0, 50, 0, 180);
myservo5.write(servoPosition);
if (yourDistance < 5)
{
myservo0.write(0);
myservo1.write(0);
myservo2.write(0);
myservo3.write(0);
myservo4.write(0);
}
else
{
photocellReading = analogRead(photocellPin0);
Serial.print(“Analog reading 0 = “);
Serial.println(photocellReading); // the raw analog reading
photocellReading = constrain(photocellReading, 0, 300);
servoPosition = map(photocellReading, 0, 1023, 0, 180);
myservo0.write(servoPosition);
photocellReading = analogRead(photocellPin1);
Serial.print(“Analog reading 1 = “);
Serial.println(photocellReading); // the raw analog reading
photocellReading = constrain(photocellReading, 0, 300);
servoPosition = map(photocellReading, 0, 300, 0, 180);
myservo1.write(servoPosition);
photocellReading = analogRead(photocellPin2);
Serial.print(“Analog reading 2 = “);
Serial.println(photocellReading); // the raw analog reading
photocellReading = constrain(photocellReading, 0, 300);
servoPosition = map(photocellReading, 0, 300, 0, 180);
myservo2.write(servoPosition);
photocellReading = analogRead(photocellPin3);
Serial.print(“Analog reading 3 = “);
Serial.println(photocellReading); // the raw analog reading
photocellReading = constrain(photocellReading, 0, 300);
servoPosition = map(photocellReading, 0, 300, 0, 180);
myservo3.write(servoPosition);
photocellReading = analogRead(photocellPin4);
Serial.print(“Analog reading 4 = “);
Serial.println(photocellReading); // the raw analog reading
photocellReading = constrain(photocellReading, 0, 300);
servoPosition = map(photocellReading, 0, 300, 0, 180);
myservo4.write(servoPosition);
}
delay(300);
}
/* boolean ping(int pingPin)
//boolean ping(int pingPin, int ledPin1, int ledPin2, int ledPin3)
{
int d = getDistance(pingPin); // cm
boolean pinActivated1 = false;
boolean pinActivated2 = false;
boolean pinActivated3 = false;
if (d < closeD) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
myservo5.write(180);
pinActivated1 = true;
pinActivated2 = false;
pinActivated3 = false;
} else {
if (d < midD) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
myservo5.write(90);
pinActivated1 = false;
pinActivated2 = true;
pinActivated3 = false;
}
else {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
myservo5.write(0);
pinActivated1 = false;
pinActivated2 = false;
pinActivated3 = true;
}
}
// return pinActivated1, pinActivated2, pinActivated3;
return pingPin;
} */
int getDistance(int pingPin)
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print(“in, “);
Serial.print(cm);
Serial.print(“cm”);
Serial.println();
return(cm); // You could also return inches
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
/*******************************************************************************/
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You could have received a copy of the GNU Lesser General Public
// License along with this code; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
/*******************************************************************************/