This is a prototype for an interactive kinetic sculpture. The users would first start the Arduino and hear a beeping. Then they are able to control how fast different part of the sculpture rotates with two knobs. LEDs shift hues according to the rpm of the motors.
This is the second this has been assembled.
/* Matthew Justice
Physical Computing
Interactive Kinetic Sculpture with leds
Do nothing machine
*/
int motorPin = 5;
int motor = 6;
//beeps on start up
void beep(unsigned char delayms) {
analogWrite(3, 20);
delay(delayms);
analogWrite(3, 0);
delay(delayms);
}
void setup() {
pinMode(motorPin, OUTPUT);
pinMode(motor, OUTPUT);
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(3, OUTPUT);
beep(100);
delay(50);
beep(60);
delay(50);
beep(125);
}
int rr = 255;
int gg = 255;
int bb = 255;
int red = 9;
int green = 10;
int blue = 11;
void loop()
{
//beep(1);
int sensor = analogRead(A0);
float rpm = sensor * (255 / 1024.0);
int sensort = analogRead(A1);
float rpmt = sensort * (255 / 1024.0);
int speeed = rpm;
int speeedt = rpmt;
analogWrite(motorPin, speeed);
analogWrite(motor, speeedt);
Serial.println(rpmt);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
int sensorValue = analogRead(A0);
float volt = sensorValue * (360 / 1024.0);
if (volt < 60) {
rr = 0;
}
if (volt >= 120 && volt <= 240 ) {
rr = 255;
}
if (volt >= 300) {
rr = 0;
}
if (volt >= 60 && volt <= 180) {
gg = 0;
}
if (volt >= 240 ) {
gg = 255;
}
if (volt < 120 ) {
bb = 255;
}
if (volt >= 180 && volt <= 300) {
bb = 0;
}
// linear color change
if (volt < 60 ) {
gg = (255 / 60) * volt;
gg = 255 - gg;
gg = abs(gg);
}
if (volt >= 120 && volt <= 180) {
bb = (255 / 60) * (volt - 120);
bb = 255 - bb;
bb = abs(bb);
}
if (volt >= 240 && volt <= 300) {
rr = (255 / 60) * (volt - 240);
rr = 255 - rr;
rr = abs(rr);
}
if (volt >= 180 && volt <= 240) {
gg = -1 * ((255 / 60) * (volt - 180));
gg = 255 - gg;
gg = abs(gg);
}
if (volt >= 60 && volt <= 120) {
rr = -1 * ((255 / 60) * (volt - 60));
rr = 255 - rr;
rr = abs(rr);
}
if (volt >= 300 && volt <= 360) {
bb = -1 * ((255 / 60) * (volt - 300));
bb = 255 - bb;
bb = abs(bb);
}
analogWrite(red, rr);
analogWrite(green, gg);
analogWrite(blue, bb);
}