lab assignment_01

Submitted by njohn on Wed, 01/30/2013 - 16:57

// description

Because I have done some experimenting with Arduino (both the microprocessor and the language) before, I elected to use this first assignment to learn a little bit about how to create recurring statements inside of the void loop in Arduino.

To do this, I chose the "while" command, setting it up so that the LED would blink more times but at a faster rate over a course of 50 cycles.  

I'm not sure if this was the easiest or most elegant solution to the task of making the LED blink at different rates for a fixed number of blinks, but it did function as I intended.  

Lastly, Elliot showed me how to use a simple "serial" command to return text to the console, so that I could diagnose a problem that was causing the program to become stuck within the second "while" statement.

 

 

// components used

1 - Arduino Uno

1 - Breadboard

1 - 330 ohm resistor

1 - Yellow LED

 

 

// code

 

 
int led = 13;
 
void setup() {                
  Serial.begin(9600);
  pinMode(led, OUTPUT);     
}
 
 
void loop() {
  
  int var = 0;
 
  Serial.println("loop");
 
  while(var<2){
    Serial.println("while 1");
    Serial.println(var);
    digitalWrite(led, HIGH);   
    delay(2500);              
    digitalWrite(led, LOW);    
    delay(1000);        
    var++;
  }
  
  while(var<10){
    Serial.println("while 2");
    Serial.println(var);
    digitalWrite(led, HIGH);
    delay(200);
    digitalWrite(led, LOW);
    delay(200);
    var++;
  }
  
    while(var<50){
    Serial.println("while 3");
    Serial.println(var);
    digitalWrite(led, HIGH);
    delay(50);
    digitalWrite(led, LOW);
    delay(50);
    var++;
  }
  
}
 
 
njohn_blink
0
Your rating: None
Drupal theme by Kiwi Themes.