//Author : Kunchala Anil
//Led Brightness control Via Serial
#define ledstep 5
int ledbrightness = 0;
int led[] = {3,5,6,9,10,11};
void setup(){
Serial.begin(9600);
for(int i=0;i<6;i++){
pinMode(led[i],OUTPUT);
}//end of for loop
}//end of setup
void loop(){
Serial.println("enter y to increse the led brightness and n to decrease it");
serial_check();
}//end of loop
//SERIAL_CHECK() FUNCTION
void serial_check(){
while(!Serial.available()){
//wait until user enters the data
}
while(Serial.available()){
char input = Serial.read();
if(input == 'y'){
increase_brightness();
}//end of if
else if(input == 'n')
{
decrease_brightness();
}//end of else if
else {
error();
}//end of else
}//end of while
}//end of serial_check() function
//INCREASE_BRIGHTNESS FUNCTION
void increase_brightness(){
if(ledbrightness < 250){
ledbrightness = ledbrightness + ledstep;
}//end of if
else
{
Serial.println("brightness is maximum resetting it to 0");
ledbrightness = 0;
}//end of else
for(int j=0;j");
Serial.print(ledbrightness);
Serial.println("");
}//end of increase_brightness() function
//MAINTAIN_BRIGHTNESS FUCNTION
void decrease_brightness(){
if(ledbrightness > 0){
ledbrightness = ledbrightness - ledstep;
}//end of if
else
{
Serial.println("brightness is zero resetting it to 250");
ledbrightness = 250;
}//end of else
for(int j=0;j");
Serial.print(ledbrightness);
Serial.println("");
}//end of maintain_brightness() function
//ERROR FUNCTION
void error(){
Serial.println("you entered a wrong character");
}//end of error function
Saturday, 4 April 2015
LED Brightness Control Via Serial.....
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment