Sunday, June 13, 2010

combined both codes and added a little of my handy work :-)

so i combined both the photo cell and the light pattern codes together. i tried to alter the code in a way so that the photo cell would recognize the PWM pins (pulse with modulation pins). the ORANGE would be my handy work, The RED would be the photocells code. My error is in The Colors of the rainbow because.....well its just...you know!!!!


/*Fireflies*/

int value;
int pwmPin = 11; // light connected to digital pin 11-- I just chose an initial value
//int ledpin2 = 9;
long time=0;
int period = 500;
int i = 0;
long blink_delay = 1000; // these must be declared as long due to the random() operation
long blink = 3;
long random_led = 55;
const byte pwmPins [] = {3, 5, 6, 9, 10, 11};

int lightpin = 0; //the ana log pin the
//photoresistor is
//connected to
//the photo resistor is not
//calibrated to any units so
//this is simply a raw sensor value (relative light)
//LED pin
int pwmpin= 11;//the pin the LED is conneced to
//we are conrtolling the brigtness so
//we use one of the PWM (pulse
//width modulation pins)
int pwmpin = 5

int pwmpin = 6

int pwmpin = 9

int pwmpin = 10

int pwmpin = 3


void setup()
{
pinMode(pwmpin, OUTPUT); //sets the led pin to
//output //nothing to setup
}

void loop()

{
int lightLevel = analogRead(lightpin); //Read the
// light level
lightLevel = map(lightLevel, 0, 900, 0, 255);
//adjust the value 0 to 900 to
lightLevel = constrain(lightLevel, 0, 255);
//make sure the value is between 0 and 255
analogWrite(ledpin, lightLevel); //Wright the value
}
{
int lightLevel = analogRead(lightpin); //Read the
// light level
lightLevel = map(lightLevel, 0, 900, 0, 255);
//adjust the value 0 to 900 to
lightLevel = constrain(lightLevel, 0, 255);
//make sure the value is between 0 and 255
analogWrite(ledpin, lightLevel); //Wright the value
}

{
choose_firefly();
fade();

blink_delay = random(500, 4001);
delay(blink_delay);
blink = random(2, 5);

}
void fade()
{
for(i=0; i<255;)
{
time = i;
value = abs(-127+127*cos(4*PI/period*i)); //the -127 value shifts the cosine curve negative with a zero initial value; abs shifts everything positive
analogWrite(pwmPin, value); // sets the value (range from 0 to 255)
delay(blink);
i++;
}
}

void choose_firefly()
{
pwmPin = pwmPins [random (0, 6)];
}

but apparentlly my work was "UNQUALIFIED"

error: expected unqualified-id before numeric constant In function 'void loop()': At global scope:

the mistake wasn't in organization but the Arduino is not recognizing or not accepting something in the code, to my understanding.

could use a little input........

otherwise I'm just stuck with a light show.

1 comment: