Sunday, February 24, 2013

LAB #7

LED sequence - pot controls sequence speed, button pressed = sequence hold.
Servo motors - triggered by sequence count #2 and 4 (green and blue).

I tried to make it so when the button was pressed on count 2 or 4, the servo motors would continue to move as long as the count remained at 2 or 4, but I couldn't get that to work.   There is some conditional I'm missing, or perhaps have placed in the wrong spot in the programming  void.loop.   Not quite sure.  I'll figure it out though.  For now though, what is here will suffice for this lab exercise.


here's the code:

////////3///////servo library, name servo motors//////
#include <Servo.h>

Servo Green;
Servo Blue;
/////////3///////////

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

int count = 0;
int dir = 1;

////////////////////
const int buttonPin = 7;
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);
  ///////////////////////////

/////////////3/////////

Green.attach(3);
Blue.attach(11);

///////////3/////////

}


void loop() {
  /////2//////////////
  potValue = analogRead(potPin);
  newValue = map(potValue, 0, 1023, 50, 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);
 
  ///////////3/////////
   Green.write(90);
  delay(500);
  Green.write(0);
  delay(10);
  ////////////3////////
  }

  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); 

///////3////////// 
  Blue.write(90);
  delay(500);
  Blue.write(0);
  delay(10);
/////3///////////
}

 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;
////////////////3///////////////
if(count==2){
    Green.write(90);
  delay(500);
  Green.write(0);
  delay(10);
}

if(count==4){
  Blue.write(90);
  delay(500);
  Blue.write(0);
  delay(10);
}
///////////3////////////////
}



   
    //analogWrite(led06, bright);

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

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("   ");
/////////////////////////////
}
}

Tuesday, February 12, 2013

LAB #5

so I took my lab #4 and and added a digital temporary push-button (normally open style in terms of the sequence).  Also added a pulsing LED to signify when the button should be pushed in order to trigger the sequence.
I removed the digitalWrite information for the sequencing LED's when the digital trigger reads : 1 (i.e. button open).
Because there is no conclusion as to what happens to the sequence when the button is not pressed, the sequence freezes in place.  Pressing the button acts as a hold-release for the sequence.

 

here's the code for it (i tried to put all the new code for this project in between lines of ////////////////  but I think I forgot to add the   ////////'s  a couple places).









 the end.


Monday, February 11, 2013

non-class related test - embedding link in text

sorry, this is non-class related.  But i need to remember how to embed public-folder links from Pantherfile into text on blogger for the class I am TA-ing for.

that is embedded in this

the end. hope this works.

Friday, February 8, 2013

LAB#4

sequencing LED's with arduino - I feel like my coding is different than the in-class example.  I couldn't remember how the direction-reversal was set up (i didn't take clear enough notes).  I feel like coding or programming or whatever it is called is starting to make sense though, so I was able to figure it out.  I liked logic... I like this in the same way.


















arduino coding:

hopefully this weekend will allow time for building an RCA sequencer... DPDT relay style, switch audio and video signals simultaneously, automatically.  I've tried building those before using metal plates and slow, heavy-duty motors---failed attempts.  I would have never thought programming such a thing digitally would be so simple.  that makes me happy and hope-full.

Tuesday, February 5, 2013

Lab #3

My first bit of programming with Arduino...  counting, making statements and exclamations about whether or not it is impressive to count.

Lab#3






Sunday, February 3, 2013

lab #2

I need an on/off indicator light for my synthesizer so i don't accidentally wear out the batteries!
I havn't put any LED's on anything in a while, so this was a great refresher!
too bright

too low

  
just right