Saturday, February 16, 2013

LAB #6

I added a potentiometer to vary the sequence speed of the last circuit.  The control pin of my pot is going to an analog in,  the arduino measures the resistance of the pot between the ground and 5v. terminal.  then I map control ratio for for the speed of the digitally triggered sequence.




here is the coding (analog in information in between :  /////////2//////////'s).  i didn't have to add very much.  I don't want to fade these LED, s because they are going to be relay on/off indicators soon (as soon as my relays come in the mail).  Fading wouldn't make sense then.

const int led01 = 5;
const int led02 = 6;
const int led03 = 7;
const int led04 = 8;
const int led05 = 9;

int count = 0;
int dir = 1;

////////////////////
const int buttonPin = 3;
int buttonPress = 0;

const int led06 = 11;
int bright = 0;
int dirB = 1;
//////////////////

///2///////////////
const int potPin = A0;
int potValue = 0;
int newValue = 0;

int dlyVar = 0;

///2//////////////

void setup() {               
 
  Serial.begin(9600);
 
  pinMode(led01, OUTPUT);    
  pinMode(led02, OUTPUT);
  pinMode(led03, OUTPUT);
  pinMode(led04, OUTPUT);
  pinMode(led05, OUTPUT);
/////////////////////////// 
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);
  ///////////////////////////
}


void loop() {
  /////2//////////////
  potValue = analogRead(potPin);
  newValue = map(potValue, 0, 1023, 100, 1000); 
 
 
  dlyVar = newValue;

Serial.print("potValue = ");
Serial.print(potValue);
Serial.print("      ");
Serial.print("newValue = ");
Serial.print(newValue);
Serial.print("           ");
  /////2//////////////
 
  //////////////////////////////
  buttonPress = digitalRead(buttonPin);
  Serial.print("buttonPress = ");
  Serial.print(buttonPress);
  Serial.print("          ");
 
 
  if(buttonPress==1){
  digitalWrite(led06, LOW);
 
  /////////////////////////////////////
 
  if(count >= 6){
   dir=-1;
  }
 
  else if(count <=0){
    dir=1;
  }
 
  count = count+1*dir;
 
  delay(dlyVar);
 
  ///^^2^^////changed delay amount to be controlled by pot////////
 
  if(count==0){
  digitalWrite(led01, LOW);               
  digitalWrite(led02, LOW);   
  digitalWrite(led03, LOW);
  digitalWrite(led04, LOW);      
  digitalWrite(led05, LOW);
  
  }
 
  else if(count==1){
  digitalWrite(led01, HIGH);              
  digitalWrite(led02, LOW);   
  digitalWrite(led03, LOW);
  digitalWrite(led04, LOW);   
  digitalWrite(led05, LOW);

  }
 
  else if(count==2){
  digitalWrite(led01, LOW);  
  digitalWrite(led02, HIGH);   
  digitalWrite(led03, LOW);
  digitalWrite(led04, LOW);      
  digitalWrite(led05, LOW);
 
  }

  else if(count==3){
  digitalWrite(led01, LOW);  
  digitalWrite(led02, LOW);   
  digitalWrite(led03, HIGH);
  digitalWrite(led04, LOW);   
  digitalWrite(led05, LOW); 
  }

  else if(count==4){
  digitalWrite(led01, LOW);  
  digitalWrite(led02, LOW);   
  digitalWrite(led03, LOW);   
  digitalWrite(led04, HIGH);   
  digitalWrite(led05, LOW); 
}

 else if(count==5){
  digitalWrite(led01, LOW);  
  digitalWrite(led02, LOW);   
  digitalWrite(led03, LOW);   
  digitalWrite(led04, LOW);   
  digitalWrite(led05, HIGH); 

}

 else if(count==6){
  digitalWrite(led01, LOW);  
  digitalWrite(led02, LOW);   
  digitalWrite(led03, LOW);   
  digitalWrite(led04, LOW);   
  digitalWrite(led05, LOW);
 }


Serial.print("sequence-count = ");
Serial.print(count);
Serial.println("      ");

}
//////////////////////////
if(buttonPress==0){
 bright = bright + dirB;

if(bright>+255){
 dirB = -1;
}

else if(bright<=0){
dirB = 1;
}

analogWrite(led06, bright);

Serial.print("sequence hold = ");
Serial.print(count);
Serial.println("   ");
/////////////////////////////
}
}

No comments:

Post a Comment