Monday, September 12, 2011

Wiring the First Surface


By using the photoresistor as a way to constantly measure sunlight throughout the day, the SmartSurface can record the lengths of day and night throughout the seasons, as the ration of sunlight to darkness changes. By using this ratio as a input, we can control the varying patterns and intensity of the lights and speed of the DC motors that would control the rotating section. Currently, the wiring is setup for only 6 lights and no DC motor. However, using a series of analog shift registers, we can achieve a modular structure that works off of only one Arduino, with only minor speed losses in response time with more modules.

Code:

//PhotoResistor Pin
int lightPin = 0;

//LED Pin
int ledPin0 = 11;
int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 6;
int ledPin4 = 5;
int ledPin5 = 3;

//counters

int led0=0;
int led0d=1;

int led1=6;
int led1d=1;

int led2=12;
int led2d=1;

int led3=18;
int led3d=-1;

int led4=12;
int led4d=-1;

int led5=6;
int led5d=-1;


void setup()
{
Serial.begin(9600);
pinMode(ledPin0, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);

}

void loop()
{
int lightLevel = analogRead(lightPin);

lightLevel = map(lightLevel, 430, 760, 1, 14);

lightLevel = constrain(lightLevel, 0, 14);

analogWrite(ledPin0, lightLevel*counter(led0,led0d));

analogWrite(ledPin1, lightLevel*counter(led1,led1d));

analogWrite(ledPin2, lightLevel*counter(led2,led2d));

analogWrite(ledPin3, lightLevel*counter(led3,led3d));

analogWrite(ledPin4, lightLevel*counter(led4,led4d));

analogWrite(ledPin5, lightLevel*counter(led5,led5d));

delay(50);
}

int counter(int& number, int& dir) {
if (number>0 && number<18) { if (dir==1) { number++; return number; } else { number--; return number; } } else if (number >= 18) {
number--;
dir=-1;
return number;
}
else if (number <= 0){ number++; dir=1; return number; } }

No comments:

Post a Comment