Arduino first programs

Pic of correct circuit (yes, it is indeed possible to set up even something this simple wrong, if you don’t know what you are doing)

Hello World!

My First Circuit

Here it is in action:

ArduinoBlink

And now with more interesting function:

ArduinoMorse

The sketch:

int UNIT = 200;
int PAUSE_INTERNAL = UNIT;
int DOT = UNIT;
int DASH = 3*UNIT;
int PAUSE_LETTER = 3*UNIT;
int A[] = {DOT, DASH}; int A_LENGTH = 2;
int M[] = {DASH, DASH}; int M_LENGTH = 2;
int E[] = {DOT}; int E_LENGTH = 1;
int J[] = {DOT, DASH, DASH, DASH}; int J_LENGTH = 4;
int V[] = {DOT, DOT, DOT, DASH}; int V_LENGTH = 4;
int S[] = {DOT, DOT, DOT}; int S_LENGTH = 3;
int O[] = {DASH, DASH, DASH}; int O_LENGTH = 3;
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
    delay(2500);

  animate(S, S_LENGTH);
  delay(PAUSE_LETTER);
  animate(O, O_LENGTH);
  delay(PAUSE_LETTER);
  animate(S, S_LENGTH);
  
  delay(2500);              
}

void animate(int* sequence, int length){
  for(int i=0; i < length; i++){
   digitalWrite(13, HIGH);

    delay(sequence[i]);
   digitalWrite(13, LOW);
    delay(PAUSE_INTERNAL);
   
  }
}
---(with credit to E. Persky, without whom I would be staring hopelessly at the screen right now)
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