Blink three time in row

I live about 30 miles north of OREILY so I drop by and bought an Arduino Started kit at the MakerSHEAD itself. Drove home and downloaded the software and copy and pasted the Blink sketch.
From purchase to blinking 2hours. Talk about instant gratification. Next stop Burning Man.

A few weeks ago I was looking for the Arduino at Fry's in Fremont. When I ask about the board they look at me as if I beamed in from another planet. They checked computer inventory, no luck. After wandering around the store I literally ran into a MakerShed kiosk made out of 2in plumbing pipe. Lots of fliers about the Arduino, a pile of Banzi books, but no Arduinos (Sad)

I am looking forward to doing very small projects and getting a better understand of how the board works. After living around computers for 50 years is cool that there are still new stuff out there

Thanks to all the Arduino folk for a very fun work of magic

Tom Marquette
Lake County California

Talk about instant gratification. Next stop Burning Man.

haha! Welcome! ;D

Welcome to the forum Tom. I think you will find the Arduino experience even better then your first impression. It opens a world of cool projects. There are so many neat application chips available these days and the Arduino makes a perfect platform to experiment with them. I don't think the electronic hobby has ever had a better outlook then it does today.

I do suggest you check out a few on-line sellers rather then only depending on local and not so local stores. Here are just a few:

http://www.seeedstudio.com/depot/

http://www.goldmine-elec.com/

And of course E-bay tends to have over 1,000 listings these days using "Arduino" as a key word search. I have found many great bulk quantity deals from Asia on commodity electronics parts (leds, resistors, caps, switches, connectors, etc) from Asia and have yet to be disappointed in quality.

Good luck and have fun

Lefty

Thing #2 got three blinks at 500 three blinks at 1500 three blinks at 500 then a 5000 delay. Look mom SaveOurShip. Finally put a LED in pin 13, wwhoo dem guy are pretty darn bright.

Bio Stuff I teach computer classes at a community college,,, but my major is in Art from SSU. How I got come to ArduinoLand was through a Wired story about Steam-punk keyboards Which lead to a Steam-punk Conn in Emeryville,ca where the guy who built the Burning man Snail Mobile was speaking. After his presentation three different folk asked Arduino questions. One are was a costumer, other a welder and the last electrical engineer, I figured this board must be usable and powerful.

Welcome, Tom.

I've never been to Burning Man (but I know exactly what it is), and I'll bet that on any given year, there are dozens, if not hundreds of Arduinos, doing crazy stuff all over the playa.

Have fun!

Thing #3 Did my name (tom marquette) in blinking mores code. Changed dots to delay 500, dashes at 1500 delays. Delays between letters are 1750. The Delay at end of loop is 5000. Delays between a dash or a dot are 250.

I am only able to count the total number of blinks (24) I lose track of the different between dot and dash very easily. It's hard to judge the time separating the end of a character string of blinks. My friend reminded me that he learned mores code by the sound of the dots and dashes. I'm thinking a single flashing light is just too hard to keep track of length of time.

What I think I am running into is the serial nature of the telegraph. In 1837 you had to push everything down one wire. The approach I'm going to try is sending dot signals to a blue LED, dashes to a red LED and spaces to a green LED. Well that's the plan ,,,, at least.

A possible project would be using a second Arduino with a photo sensor to measure the blinks and output the letters. The Arduino would do a way better job of noting the passage of time.

Tom,

This form further down this forums postings.

/* =============================================================================
 * File - morse.pde
 * -----------------------------------------------------------------------------
 * Code formatted assuming 80 characters screen width
 *
 * Naming Convention
 *  e_      enumeration
 *  g_      global
 *  k_      constant
 *
 *  dt      delta time
 */


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

#include "WProgram.h"

#include <ctype.h>


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

struct encoding_t
{
    const char              ascii;
    const unsigned short    encoding;
};


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

enum { e_EOS = 0, e_DOT, e_DASH, eMASK };


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

static const encoding_t  morse_encodings[] =
{
    // a string of 2-bit values encode the morse sequence, LSb -> MSb
    // 00   end-of-sequence
    // 01   '.'
    // 10   '-'
    // 11   unused

    
    // --- Numeric
      { '0',    0x02AA }    // "-----"
    , { '1',    0x02A9 }    // ".----"
    , { '2',    0x02A5 }    // "..---"
    , { '3',    0x0295 }    // "...--"
    , { '4',    0x0255 }    // "....-"
    , { '5',    0x0155 }    // "....."
    , { '6',    0x0156 }    // "-...."
    , { '7',    0x015A }    // "--..."
    , { '8',    0x016A }    // "---.."
    , { '9',    0x01AA }    // "----."
    
    // --- Alphabetic
    , { 'A',    0x0009 }    // ".-"
    , { 'B',    0x0056 }    // "-..."
    , { 'C',    0x0066 }    // "-.-."
    , { 'D',    0x0016 }    // "-.."
    , { 'E',    0x0001 }    // "."
    , { 'F',    0x0065 }    // "..-."
    , { 'G',    0x001A }    // "--."
    , { 'H',    0x0055 }    // "...."
    , { 'I',    0x0005 }    // ".."
    , { 'J',    0x00A9 }    // ".---"
    , { 'K',    0x0026 }    // "-.-"
    , { 'L',    0x0059 }    // ".-.."
    , { 'M',    0x000A }    // "--"
    , { 'N',    0x0006 }    // "-."
    , { 'O',    0x002A }    // "---"
    , { 'P',    0x0069 }    // ".--."
    , { 'Q',    0x009A }    // "--.-"
    , { 'R',    0x0019 }    // ".-."
    , { 'S',    0x0015 }    // "..."
    , { 'T',    0x0002 }    // "-"
    , { 'U',    0x0025 }    // "..-"
    , { 'V',    0x0095 }    // "...-"
    , { 'W',    0x0029 }    // ".--"
    , { 'X',    0x0096 }    // "-..-"
    , { 'W',    0x00A6 }    // "-.--"
    , { 'Z',    0x005A }    // "--.."
    
    // --- Punctuation
    , { ',',    0x0A5A }    // "--..--"
    , { '.',    0x0999 }    // ".-.-.-"
    , { ':',    0x056A }    // "---..."
    , { '?',    0x05A5 }    // "..--.."
    , { '-',    0x0956 }    // "-....-"
    , { '/',    0x0196 }    // "-..-."
    , { '(',    0x09A6 }    // "-.--.-"
    , { ')',    0x09A6 }    // "-.--.-"
    
    // --- ARDUINO Windows IDE has problems with escaped ascii literals!
#if 0
    , { '\'',   0x06A9 }    // ".----."
    , { '\"',   0x0699 }    // ".-.--."
#endif
};

const int pin = 13;


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

int g_dtDot;
int g_dtDash;
int g_dtChar;
int g_dtWord;


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

static void dot()
{
    digitalWrite(pin, HIGH);
    delay(g_dtDot);
    
    digitalWrite(pin, LOW);
}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

static void dash()
{
    digitalWrite(pin, HIGH);
    delay(g_dtDash);
    
    digitalWrite(pin, LOW);
}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

static void blinkSequence(unsigned short encoding)
{
    do
    {
        switch ( encoding bitand eMASK )
        {
            case e_DOT: dot();      break;
            case e_DASH:dash();     break;
            default:                break;
        }
        
        encoding >>= 2;

        if ( encoding ) { delay(g_dtDot); }

    } while ( e_EOS != (encoding bitand eMASK) );
}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

static void blinkCharactor(char ch)
{
    const int cEntries = sizeof(morse_encodings) / sizeof(morse_encodings[0]);
    
    for ( int i = 0; i < cEntries; i++)
    {
        if ( ch == morse_encodings[i].ascii )
        {
            blinkSequence(morse_encodings[i].encoding);
            return;
        }
    }
}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

void setTimings(int dt)
{
    g_dtDot     = dt;
    g_dtDash    = 3 * dt;
    g_dtChar    = 3 * dt;
    g_dtWord    = 7 * dt;
}


/* =============================================================================
 * -----------------------------------------------------------------------------
 * Any speed greater than 10-15 words per minute will be hard to read on an LED
 */

void setSpeedWordsPerMinute(int wpm)
{
#define WPM_MAX     (150)
    
    const unsigned long k_MPM           = (60 * 1000);  // millisec's per minute
    
    const unsigned long k_DOT           = 1;
    const unsigned long k_DASH          = 3;
    const unsigned long k_INTRA_SEQ     = 1;
    const unsigned long k_INTRA_CHAR    = 1;
    
    const char          standard[]      = { "PARIS" };
    
    // --- check and enforce words per minute boundries

    if ( wpm < 1 )          { wpm  = 1; }
    if ( wpm > WPM_MAX )    { wpm  = WPM_MAX; }
    

    // --- count 'dot' length of 'standard' word

    const char*         ptr = standard;
    unsigned long       dpw = 0;            // 'dot's per word
    char                ch;
    while ( ch = *ptr++ )
    {
        const int cEntries = sizeof(morse_encodings) / sizeof(morse_encodings[0]);
        
        for ( int i = 0; i < cEntries; i++)
        {
            if ( ch == morse_encodings[i].ascii )
            {
                unsigned short  encoding    = morse_encodings[i].encoding;
                
                do
                {
                    switch ( encoding bitand eMASK )
                    {
                        case e_DOT:     dpw += k_DOT;   break;
                        case e_DASH:    dpw += k_DASH;  break;
                        default:                        break;
                    }

                    encoding >>= 2;

                    if ( encoding ) { dpw += k_INTRA_SEQ; }

                } while ( e_EOS != (encoding bitand eMASK) );
            }
        }
        
        if ( *ptr ) { dpw += k_INTRA_CHAR; }
    }
    
    setTimings(k_MPM / (wpm * dpw));
}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

void loop()
{
    const char      message[]   = { "ARDUINO ROCKS" };
    const char*     ptr         = message;
    
    char            ch;
    while ( ch = *ptr++ )
    {
        blinkCharactor(((isalpha(ch)) ? toupper(ch) : ch));
        delay(((' ' == *ptr) ? g_dtWord : g_dtChar));
    }
    
    // 3 SECONDS
    const int   dtMessageDelay = (3 * 1000);
    delay(dtMessageDelay);
}


/* =============================================================================
 * -----------------------------------------------------------------------------
 */

void setup()
{
    pinMode(ledPin, OUTPUT);

    setSpeedWordsPerMinute(25);
}

Thank you lloyddean I will try the sketch after I get a handle on this programing zeitgeist. One of my goals is to Lego the code, that is small understandable chucks of code. Sort of fifth grader level. Not to say loading arrays and sub calls isn't good programing practice. For myself I need some one to one mapping before move to the next level of interaction. The getting it to do and the knowning how it got to be done often is a matter of a whole lot of repeated baby steps.

THING # 3 Three LED in a row. The thought given form was send dash signals on pin 2 send dot signals on pin 12 and send end of charterer signal on pin 3. Up until this point I had not put any component into the breadboard. I followed the drawing in the starter kit book and wasn't getting much luck with the resisters going horizontal on the breadboard. The LED was barely glowing if glowing at all. Further the drawing of the + and - rails where reversed on my breadboard. Now for a person with years of electronic training this would not be a problem. but for someone with Zero experience. this added FUD to the project. I googled the breadboards manufacture in Ill. the markings of +red -blue matched. I looked a bunch of Youtube and the breadboard matched. So I figure I take a look at the Arduino tutorials and low one showed a drawing with all the resisters place vertically on the breadboard. I pulls out all the LEDs and jumpers and resisters.

By this time the legs on the poor resister were bent, kinked, and bowed, the jumper were crossing over each other and the jumpers from the resisters to the -blue rail were at 20 degree diagonals, but they all blink at the same time full brightness. It looks very ugly but I have a red a blue and a green blinking.

Next thing: send mores code to the LEDs. I think I will call the thing a Arduinograph. ha ha

Tom

Tom. Why not get a little piezo speaker and then you can hear the morse code.

They are really cheap.

Seems like you are enjoying yourself no matter what you are up to.

Keep it up!

Thing #4 mores code using red blue and green LEDs

Where I started I noted mores code uses a max of four signals to represent a letter. So I created four arrays 26 element long. I lined all four up and put pin value vertically
12,
2,
3,
3,
would product red blue green green

Next I created four arrays to hold number of millisecond the pin was on
1000,
1000,
0,
0,
which should have done red on for a second off a second blue on for a second off for a second the third and fourth times set of zero would prevent the LEDs from lighting up.

Then a green LED would automatically turn on to show the character was finished

Two things that went very wrong: first the array started counting at element zero so it didn't match up with the array index in my for loop. I tried starting the for loop at 1 but for some reason it returned the second element value instead of element first in the zero position. In the end I just put a dummy value in the first element of all four arrays.

The next thing that was a surprise a delay of zero still caused the green LEDs to flash once. Not good.
So I change the digitalwrite (LEDpin, HIGH) to digitalwrite(red, HIGH) and digitalwrite(blue, HIGH) and load the variable to: red =2 or blue=12 to change where the signal where being sent. This cause the LED to glow at a quarter brightness and still flash once. Not Good!

I took care of the single flash and dimming by pass a pin value with a #define red 2 and a #define blue 12 and #define green 10 (a pin not connected). I have no idea if this is proper coding, but it seem to work
Personally it feel like a hack. It would have been nice to make a function call and just pass three arguments. So far I have not found anything at the arduino sight about function , of course it might have merely failed to located that information.

As the started to change my perspective of LED pins I started to question how they should be labeled in the digitalwrite function. What started as a physical mapping to pin location became more of a logical reference to a color swamping container, so I changed the variable name of all three pinModes to blinker1 blinker2 and blinker3 so each LED had a output set red blue green respectively, but could be reassigned with a #define command.

I loaded the arrays first[] second[] third[] four[] with values of 12 for red, values of 2 for blue and values of 3 for green. I loaded arrays kron2[] kron3[] kron4[] with values of 1000 and values of O. There is no array kron1[] because there is always at least on dot or dash in mores code 1000 on 1000 off.

I have eight digitalwrite statements all set to blinker1 to turn on a LED and one to turn it off

I have four #define blinker1 commands that get the pin value from my first four arrays.

I also have four variables called one, two, tri, qud that get pin numbers
I have four variables called time1 time2 timer3 timer4 that get delay in milliseconds or zero delays
There are three variables: length, i, x one for the length of the for loop, one to index counter and one for indexes for the first[x] second[x] third[x] fourth[x]

One last adjustment needed to be put in place to reduce the ASCII code value to the numeric position of each letter, take for example the ASCII code for 'a' is 97 but it is the first code in the mores code list. So I just subtracted 96 and all the alphabet followed along rather nicely.

Ok so how does this thing work. The array letters[] ={'a','b','c'} has three elements and we set the loop to length =3 The for loop uses a variable name “i” to count up to three. The first time “i” is equal to the number 1 so the follow happen x = letters –96 so x = letter[1] –96 Which is: x = 97 – 96 . The next array is: one = first[x] which is: one = first[1] thus one = 12 ( the location of the red LED) Next the define blinker1 one became #define blinker1 12 this passed on to digitalwrite(blinker1, HIGH) which could be seen as digitalwrite(12, HIGH) pinMode(12., output)
two = second[1] loads up two = 2 then #define blinker 2 finally digitalwrite(2, HIGH)
tri = third[1] loads up tri = 10 then #define blinker 10 finally digitalwrite(10, HIGH) a nonconnected pin
qud = four[1] loads up qud = 10 then #define blinker 10 finally digitalwrite(10, HIGH) a nonconnected pin
digitalWrite(blinker3, HIGH); delay(1000); is the last statement before the loop goes to i=2
one = first[2] will become one = 2
two = second[2] will become one = 12
tri = third[2] will become one = 10
qud = fourth[2] will become one = 10
one = first[3] will become one = 2
two = second[3] will become one = 12
tri = third[3] will become one = 2
qud = fourth[3] will become one = 12 blue red blue red dash dot dash dot “b”

Oh my ---my spelling really suck. Sorry
mores code Morse Code oh well closer editing next time
I tend to drop my 's' 'ed' and 'ing'
bad brain wiring.

Just found the Function page woo hooo

Going to to rewrite the Morse Code sketch and see if I can reduce its size with some function calls. Will post current sketch described in last post. Just to tire to get it up.

Here be the sketch of the morse code blinker RRRR.

red LED to pin 12
blue LED to pin 2
green LED to pin 3

remember the resisters and ground
(you knew that already)
Have fun changing the length of the message
in the letters[] array
remember the '{' curly brackets separates words
and the first character in the array is dummy value
I used a x and may want some other character.

/*
arduinograph_Eight_Arrays

Takes a user define message in an array
and outputs it as moris code

red LEDs represent dots
blue LEDs represent dashs
green LEDs show the end of character code

The end of words are represent by three
blinks of the green LED.

The end of the messsage is represent by all
three LEDs blinking similtainiously.

===========================================
Each letter of the message should be contained
with single quotes follow by a comma, but no
comma after the last letter of the message.

Type a { forward curly brackets between words.

Always begin the array with the first element
as: 'x', This allows the array to syn to the
for loop. My bad.

jume 7 2010 Tom Marquette
*/

int blinker1 = 12; // LED red connected to pin 12
int blinker2 = 2; // LED blue connected to pin 2
int blinker3 = 3; // LED green connected to pin 3

int time1 = 1000; // this delay is set for 1000
int time2 = 1000; // sets delay to zero for any code having a single signal value comes from kron2 array
int time3 = 1000; // sets delay to zero for any code having two signals value comes from kron3 array
int time4 = 1000; // sets delay to zero for any code having three signals value comes from kron4 array

int one = 0; // sets pin number from value stored in first array
int two = 0; // sets pin number from value stored in second arrray
int tri = 0; // sets pin number from value stored in third array
int qud = 0; // sets pin number from value stored in fourth array

int letters [] = {'x','a','r', 'd','u','i','n','o','{','d','u','e','m','i','l','i','a','n','o','v','e'};

int length = 20; // number of letters in message (not including the first element 'x'

int first [28] = {10, 12, 2, 2, 2, 12, 12, 2, 12, 12, 12, 2, 12, 2, 2, 2, 12, 2, 12, 12, 2, 12, 12, 12, 2, 2, 2, 3};
int second [28] = {10, 2, 12, 12, 12, 10, 12, 2, 12, 12, 2, 12, 2, 2, 12, 2, 2, 2, 2, 12, 10, 12, 12, 2, 12, 12, 2, 3};
int third [28] = {10, 10, 12, 2, 12, 10, 2, 12, 12, 10, 2, 2, 12, 10, 10, 2, 2, 12, 12, 12, 10, 2, 12, 2, 12, 2, 12, 10};
int fourth [28] = {10, 10, 12, 12, 10, 10, 12, 10, 12, 10, 2, 10, 12, 10, 10, 10, 12, 2, 10, 10, 10, 10, 2, 10, 2, 2, 12, 10};

int kron2 [28] = {0, 1000, 1000, 1000, 1000, 0, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 0, 1000, 1000, 1000, 1000, 1000, 1000, 500};
int kron3 [28] = {0, 0, 1000, 1000, 1000, 0, 1000, 1000, 1000, 0, 1000, 1000, 1000, 0, 0, 1000, 1000, 1000, 1000, 1000, 0, 1000, 1000, 1000, 1000, 1000, 1000, 500};
int kron4 [28] = {0, 0, 1000, 1000, 0, 0, 1000, 0, 1000, 0, 1000, 0, 1000, 0, 0, 0, 1000, 1000, 0, 0, 0, 0, 1000, 0, 1000, 1000, 1000, 0};

int i ;
int x ;
void setup() {

pinMode(blinker1, OUTPUT);
pinMode(blinker2, OUTPUT);
pinMode(blinker3, OUTPUT);

}

void loop() {

for (int i=1; i <= length; i++){

x = letters*-96;*

  • one = first[x];*

  • two = second[x];*

  • tri = third[x];*

  • qud = fourth[x];*

  • time2 = kron2[x];*

  • time3 = kron3[x];*

  • time4 = kron4[x];*

  • #define blinker1 one*

  • digitalWrite(blinker1, HIGH); delay(time1); // first*

  • digitalWrite(blinker1, LOW); delay(time1);*

  • #define blinker1 two *

  • digitalWrite(blinker1, HIGH); delay(time2); // second*

  • digitalWrite(blinker1, LOW); delay(time2);*

  • #define blinker1 tri *

  • digitalWrite(blinker1, HIGH); delay(time3); // thrid*

  • digitalWrite(blinker1, LOW); delay(time3);*

  • #define blinker1 qud *

  • digitalWrite(blinker1, HIGH); delay(time4); // fourth*

  • digitalWrite(blinker1, LOW); delay(time4);*

  • digitalWrite(blinker3, HIGH); delay(1000); // end of character *

  • digitalWrite(blinker3, LOW); delay(1000);*
    }

  • #define blinker1 12*

  • #define blinker2 2*

  • #define blinker3 3*

  • digitalWrite(blinker1, HIGH); // end of message*

  • digitalWrite(blinker2, HIGH); *

  • digitalWrite(blinker3, HIGH); *

  • delay(1000);*

  • digitalWrite(blinker1, LOW);*

  • digitalWrite(blinker2, LOW);*

  • digitalWrite(blinker3, LOW); *

  • delay(6000);*

}