Michael, Jonathan, and myself decided that we wanted to do something with visualizing presence withing particular rooms at ITP. We decided on building a pendulum like contraption that would dispense either red, green, or blue sand according to input recieved from different rooms around the floor. Building the contraption to properly dispense the sand proveded to be one of the trickiest parts of the project and so we set out on developing the device first. Our solution involved rotating discs with a servo in such a manner that holes would line up under soda bottles filled with sand. With a little bit of tweaking we got things runing smoothy. Photocells (and one microphone) acted as input sending a character of either ‘r’, ‘g’, ‘b’ . Here is the code of the actutator bit of the project:
char red = ‘r’;
char green = ‘g’;
char blue = ‘b’;
char def = ‘d’;
int servoPin = 2; // Control pin for servo motor
int minPulse = 500; // Minimum servo position
int maxPulse = 2500; // Maximum servo position
int pulse = 0; // Amount to pulse the servo
long lastPulse = 0; // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses
char analog_read;
char inChar;
//char analogValueG = ‘A’; // the value returned from the analog sensor
int analogPin = 0; // the analog pin that the sensor’s on
int analogValueB = 0;
int analogValueR = 0;
int analogValueG = 0;
int analogValueD =0;
void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulse = minPulse; // Set the motor position value to the minimum
Serial.begin(9600);
}
void loop() {
analogValueG = 437;
analogValueB = 0;
analogValueR = 881;
analogValueD = 200;
pulse = map(analogValueR,0,1023,minPulse,maxPulse); // convert the analog value
analog_read = inChar;
if (Serial.available()) {
inChar = Serial.read();
Serial.flush();
}
else
{
//inChar=’d';
}
//Serial.println(inChar);
//Serial.println(analog_read);
if (analog_read == red) {
pulse = map(analogValueR,0,1023,minPulse,maxPulse);
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() – lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
// to a range between minPulse
} // and maxPulse.
if (analog_read == green) {
pulse = map(analogValueG,0,1023,minPulse,maxPulse);
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() – lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}
if (analog_read == def) {
pulse = map(analogValueD,0,1023,minPulse,maxPulse);
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() – lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}
if (analog_read == blue) {
pulse = map(analogValueB,0,1023,minPulse,maxPulse);
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() – lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}
/*delay(200);
pulse = map(analogValueD,0,1023,minPulse,maxPulse);
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() – lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last
*/
//}
//delay(20);
/*
pulse = map(analogValueD,0,1023,minPulse,maxPulse);
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() – lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last
*/
// }
//Serial.flush();
}
/*
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() – lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}
*/