Pages: [1]   Go Down
Author Topic: Make a program inside arduino for a Ldr an leds  (Read 640 times)
0 Members and 1 Guest are viewing this topic.
paris
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: May 16, 2008, 05:28:17 pm by retake77 » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have an extra "{" here:

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

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

and it should compile

Logged

Pages: [1]   Go Up
Jump to: