Calling Functions.


hey guys,

ive been dabbling in arduino little bit , ive decided id try make candle responds inputs serial monitor.

i've made functions high , low intensity settings, "off" setting. can program read serial inputs , reply corresponding messages code wont loop called functions make led's flickering.

when tried using while loop , while loop 1 function loop program stop reading serial inputs , setting wont change.

any chance can me out/point me in direction of post may educate me?

cheers.
h

p.s. here's code.

 //eeprom stores small amounts of data when power goes off. (i.e. rgb values)               

#define rpin 11
#define gpin 6
#define bpin 9
#define candlepin 5
#define delaytime 20

int flame = random(80,255);
char serialinput;
char candlesetting;

void setup() {                                     // put setup code here, run once:
 
 serial.begin(9600);
 
 pinmode (rpin, output);
 pinmode (gpin, output);
 pinmode (bpin, output);

 serial.println(f("ready instruction"));
}

void loop() {                     
 
checkserialinput();         


if (candlesetting=='h'){                     
  serial.println("candle on high");
  delay(50);
  candlelighthigh();
 
}


if(candlesetting == 'l'){
  serial.println ("candle on low");
  delay(50);
  candlelightlow();

} else if(candlesetting  == '0'){
  serial.println ("candle in off.");
  delay(50);
  candlelightoff();
}


}




//////////////////////////functions///////////////////////////

void checkserialinput() {
  if (serial.available()){     
  serialinput= serial.read();         
  candlesetting=serialinput;
}
}

void candlelighthigh () {

  analogwrite(rpin, flame);
  analogwrite(gpin, flame/3);
  delay(delaytime);
 
}


void candlelightlow () {
  analogwrite(rpin, flame/10);
  delay(delaytime);
  analogwrite(gpin, flame/20);
  delay(delaytime);

}


void candlelightoff(){
  analogwrite(rpin, low);
  analogwrite(gpin, low);
  analogwrite(bpin, low);
}
 

 

read this: read before posting programming question

specifically part using code tags.


Arduino Forum > Using Arduino > Programming Questions > Calling Functions.


arduino

Comments