Go Down

Topic: Make a program inside arduino for a Ldr an leds (Read 723 times) previous topic - next topic

retake77

May 16, 2008, 11:28 pm Last Edit: May 17, 2008, 12:28 am by retake77 Reason: 1
Hello I 'm just a beginner,
I have a arduino BT. I would like to do something easy with the LDR, but I m very new at this... please help me.
I plugged an LDR on analog in 2 and a led on digital 9 wich I use as PWM.
I tried on Max/Msp and I did a litle program on Max that says if the sensor LDR has maximum of light, so it do not enlight the Leds. And in the contrary if you put your finger into it (no light) so the led shines... and in the middle the PWm do his variable job .
So n[img]ow I 'm trying to do this program but for the arduino, and I m very bad at it... I took an old program fom Barragan and tried to mixed up with the squidbee program...
but my arduino 11 says all the times errors like :

In function 'void loop()':
error: a function-definition is not allowed here before '{' tokenCouldn't determine program size: hardware/tools/avr/bin/avr-size: '/tmp/build31835.tmp/led-light-sensors.hex': No such file


and my program is this one :

// Fading LED
// by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>

int value = 0;                            // variable to keep the actual value
int ledpin = 9;                           // light connected to digital pin 9
int LDR = 2;       // select the input pin for the LDR
int val = 0;       // variable to store the value coming from the sensor


void setup()
{
pinMode(LDR, INPUT);       // declare the LDR as an INPUT
}

void loop()
{   val = analogRead(LDR);       // read the value from the sensor


{
 for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
 {
   analogWrite(ledpin, value);           // sets the value (range from 0 to 255)
   delay(90);                            // waits for 30 milli seconds to see the dimming effect
 }
 for(value = 255; value >=0; value-=5)   // fade out (from max to min)
 {
   analogWrite(ledpin, value);
   delay(90);
 }  
}

please could anyone help me
thanx a lot

phineus

You have an extra "{" here:

Code: [Select]
{
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
{


delete the "{" above: for(value = 0....

and it should compile


Go Up