Simple Fading Code



ok, iv had arduino 2 months , iv made around 10, 15 little arduino projects find on net, have copy , past code, , follow schematics.

but

i want start learning write own, , built thing bed, 6 blue led's

iv used code makes fade in , out, , boy dose awsome in bedroom, have little more controll on out having plug computer change speed of fading in , out.

so tryed merge fading source code ;
http://arduino.cc/en/tutorial/fading

with analoginput source code;
http://arduino.cc/en/tutorial/analoginput

and heres got
code: [select]

int sensorpin = 0;    // select input pin potentiometer
int ledpin = 9;      // select pin led
int sensorvalue = 0;  // variable store value coming sensor

void setup()  {
  // nothing happens in setup
}

void loop()  {
  // fade in min max in increments of 5 points:
  for(int fadevalue = 0; fadevalue <= 255; fadevalue +=analogread(sensorpin); ) {
    // sets value (range 0 255):
    analogwrite(ledpin, fadevalue);        
    // wait 30 milliseconds see dimming effect    
    delay(30);                            
  }

  // fade out max min in increments of 5 points:
  for(int fadevalue = 255 ; fadevalue >= 0; analogread(sensorpin);) {
    // sets value (range 0 255):
    analogwrite(ledpin, fadevalue);        
    // wait 30 milliseconds see dimming effect    
    delay(30);                            
  }
}



can 1 please tell me iv fucked ?

i know simple arduino project, yer.
i hope 1 can please help

first of need put analog value pot in delay function , not loop.
now pot give control range 0-1023, , value go delay.
so needs :
delay(analogread(sensorpin));

you can use map function set different range of values delay, go reference page , read it.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Simple Fading Code


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums