comment 0

Physical Computing [Lab 01]: Blink

For this term’s Physical Computing module (the final module of my MA 😥 ) I’ll be keeping a log of the work that we do in class, and the lab assignments. Hopefully it’ll be interesting to see the development from learning the basics all the way through to the final result!

For the first week we completed the “Hello World” of the physical computing arena: the LED blink. When I made my first LED blink back in undergrad, I remember it feeling absolutely magical. This code that I had written on the computer was making something happen in real life!! CRAZY! (And don’t even get me started on my first servo…)

So, to spice things up a bit (and because I had a raucous headache) I decided to make a little SOS beacon.

Week 1 SOS Blink

The code can be downloaded from my GitHub, or copied below.

First I create a boolean called ‘sign’, which controls whether the light should signal a dot (0) or a dash (1). I then have an array, called ‘pattern’, in which I store the various dots and dashes to signal S.O.S. A for loop iterates through the array, calling the respective dot() and dash() methods as appropriate. Simple!

See you next week!

/*
  SOS Blink
 Repeatedly flashes SOS in morse code.
 
 Based on the Arduino Blink code by Scott Fitzgerald.
 */

boolean sign; // 0 = dot, 1 = dash
int pattern[9]; // pattern of dots and dashes


void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
  
  sign = 0;
  
  pattern[0] = 0;
  pattern[1] = 0;
  pattern[2] = 0;
  pattern[3] = 1;
  pattern[4] = 1; 
  pattern[5] = 1;
  pattern[6] = 0;
  pattern[7] = 0;
  pattern[8] = 0;  
}

// the loop function runs over and over again forever
void loop() {
 
  for (int i = 0; i<9; i++){
   
    sign = pattern[i];
    
    if (sign){dash();}
    if (!sign){dot();}
  }
  
  delay(1000);              // wait for a second

}

void dot() {
 
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(100);              // wait for a second
}

void dash() {
   
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(400);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(100);              // wait for a second
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s