Proyecto Construcción de un Beacon + Carrier

con una Placa Arduino.

 

hardware

http://www.dx.com/p/arduino-duemilanove-2009-avrmega328p-pu-with-usb-cable-118036#.VSlshnnwuM8

 

Codigo:

 

——————————————————-

//
// Simple Arduino Morse Beacon
// Written by CA3SOC
// Email: raulzona12@gmail.com
//
//
//
struct t_mtab { char c, pat; } ;

struct t_mtab morsetab[] = {
{‘.’, 106},
{‘,’, 115},
{‘?’, 76},
{‘/’, 41},
{‘A’, 6},
{‘B’, 17},
{‘C’, 21},
{‘D’, 9},
{‘E’, 2},
{‘F’, 20},
{‘G’, 11},
{‘H’, 16},
{‘I’, 4},
{‘J’, 30},
{‘K’, 13},
{‘L’, 18},
{‘M’, 7},
{‘N’, 5},
{‘O’, 15},
{‘P’, 22},
{‘Q’, 27},
{‘R’, 10},
{‘S’, 8},
{‘T’, 3},
{‘U’, 12},
{‘V’, 24},
{‘W’, 14},
{‘X’, 25},
{‘Y’, 29},
{‘Z’, 19},
{‘1’, 62},
{‘2’, 60},
{‘3’, 56},
{‘4’, 48},
{‘5’, 32},
{‘6’, 33},
{‘7’, 35},
{‘8’, 39},
{‘9’, 47},
{‘0’, 63}
} ;

#define N_MORSE  (sizeof(morsetab)/sizeof(morsetab[0]))

#define SPEED  (12)
#define DOTLEN  (1200/SPEED)
#define DASHLEN  (3*(1200/SPEED))

int LEDpin = 13 ;

void
dash()
{
digitalWrite(LEDpin, HIGH) ;
delay(DASHLEN);
digitalWrite(LEDpin, LOW) ;
delay(DOTLEN) ;
}

void
dit()
{
digitalWrite(LEDpin, HIGH) ;
delay(DOTLEN);
digitalWrite(LEDpin, LOW) ;
delay(DOTLEN);
}

void
send(char c)
{
int i ;
if (c == ‘ ‘) {
Serial.print(c) ;
delay(7*DOTLEN) ;
return ;
}
for (i=0; i<N_MORSE; i++) {
if (morsetab[i].c == c) {
unsigned char p = morsetab[i].pat ;
Serial.print(morsetab[i].c) ;

while (p != 1) {
if (p & 1)
dash() ;
else
dit() ;
p = p / 2 ;
}
delay(2*DOTLEN) ;
return ;
}
}
/* if we drop off the end, then we send a space */
Serial.print(“?”) ;
}

void
sendmsg(char *str)
{
while (*str)
send(*str++) ;
Serial.println(“”);
}

void setup() {
pinMode(LEDpin, OUTPUT) ;
Serial.begin(9600) ;
Serial.println(“Simple Arduino Morse Beacon v0.0”) ;
Serial.println(“Written by Mark VandeWettering <k6hx@arrl.net>”) ;
Serial.println(“Check out my blog @ http://brainwagon.org&#8221;) ;
Serial.println(“”) ;
}

void loop() {
// DURACION DEL CARRIER
digitalWrite (LEDpin,  HIGH) ;
delay (5000) ;
// PAUSA DESPUES DEL CARRIER
digitalWrite (LEDpin, LOW);
delay (3000) ;
// PROGRAMACION DE INFO
sendmsg(“V V V DE CA3SOC/BCN FF46 “) ;
delay(6000) ;
}

—————————————————————-

Arduino Nano salida A0 a + y RXD a –

//Adapted from code acquired at https://gist.github.com/madc/4474559

#include &lt;MicroView.h&gt;				// include MicroView library
#define PIN_OUT        0
//Define unit length in ms
#define UNIT_LENGTH    130
String BeaconText = "DE CA3SOC/B       ";
//Build a struct with the morse code mapping
static const struct {const char letter, *code;} MorseMap[] =
{
	{ 'A', ".-" },
	{ 'B', "-..." },
	{ 'C', "-.-." },
	{ 'D', "-.." },
	{ 'E', "." },
	{ 'F', "..-." },
	{ 'G', "--." },
	{ 'H', "...." },
	{ 'I', ".." },
	{ 'J', ".---" },
	{ 'K', "-.-" },
	{ 'L', ".-.." },
	{ 'M', "--" },
	{ 'N', "-." },
	{ 'O', "---" },
	{ 'P', ".--." },
	{ 'Q', "--.-" },
	{ 'R', ".-." },
	{ 'S', "..." },
	{ 'T', "-" },
	{ 'U', "..-" },
	{ 'V', "...-" },
	{ 'W', ".--" },
	{ 'X', "-..-" },
	{ 'Y', "-.--" },
	{ 'Z', "--.." },
	{ ' ', "     " }, //Gap between word, seven units 

	{ '1', ".----" },
	{ '2', "..---" },
	{ '3', "...--" },
	{ '4', "....-" },
	{ '5', "....." },
	{ '6', "-...." },
	{ '7', "--..." },
	{ '8', "---.." },
	{ '9', "----." },
	{ '0', "-----" },

	{ '.', "·–·–·–" },
	{ ',', "--..--" },
	{ '?', "..--.." },
	{ '!', "-.-.--" },
	{ ':', "---..." },
	{ ';', "-.-.-." },
	{ '(', "-.--." },
	{ ')', "-.--.-" },
	{ '"', ".-..-." },
	{ '@', ".--.-." },
	{ '&amp;', ".-..." },
	{ '/', "-..-."}
};

void setup()
{
  pinMode( PIN_OUT, OUTPUT );
  digitalWrite( PIN_OUT, LOW );
  pinMode( PIN_A1, OUTPUT );
  digitalWrite( PIN_A1, LOW );

}

void loop()
{
	uView.begin();				// start MicroView
	uView.clear(PAGE);			// clear page
	uView.print(BeaconText);	// display Message
	uView.rectFill( 0, 0, 64, 48);
	uView.display();

// portadora delay
        delay (10);
        digitalWrite( PIN_A1, HIGH );
        digitalWrite( PIN_OUT, LOW );
        delay (5000);
        digitalWrite( PIN_A1, LOW );
        digitalWrite( PIN_OUT, HIGH );
        delay (1500);

  String morseWord = encode("V V V DE CA3SOC/B CA3SOC/B FF46RJ       ");

  for(int i=0; i&lt;=morseWord.length(); i++)
  {
    switch( morseWord[i] )
    {
      case '.': //dit
        digitalWrite( PIN_A1, HIGH );
        digitalWrite( PIN_OUT, LOW );
        uView.rectFill( 0, 0, 64, 48);
        uView.display();
        delay( UNIT_LENGTH );
        digitalWrite( PIN_A1, LOW );
        digitalWrite( PIN_OUT, HIGH );
        uView.clear(PAGE);			// clear page
        uView.display();
        delay( UNIT_LENGTH );

        break;

      case '-': //dah
        digitalWrite( PIN_A1, HIGH );
        digitalWrite( PIN_OUT, LOW );
        uView.rectFill( 0, 0, 64, 48);
        uView.display();
        delay( UNIT_LENGTH*3 );
        digitalWrite( PIN_A1, LOW );
        digitalWrite( PIN_OUT, HIGH );
         uView.clear(PAGE);			// clear page
        uView.display();
        delay( UNIT_LENGTH );

        break;

      case ' ': //gap
        delay( UNIT_LENGTH );
    }
  }
}

String encode(const char *string)
{
  size_t i, j;
  String morseWord = "";

  for( i = 0; string[i]; ++i )
  {
    for( j = 0; j &lt; sizeof MorseMap / sizeof *MorseMap; ++j )
    {
      if( toupper(string[i]) == MorseMap[j].letter )
      {
        morseWord += MorseMap[j].code;
        break;
      }
    }
    morseWord += " "; //Add tailing space to seperate the chars
  }

  return morseWord;
}

String decode(String morse)
{
  String msg = "";

  int lastPos = 0;
  int pos = morse.indexOf(' ');
  while( lastPos &lt;= morse.lastIndexOf(' ') )
  {
    for( int i = 0; i &lt; sizeof MorseMap / sizeof *MorseMap; ++i )
    {
      if( morse.substring(lastPos, pos) == MorseMap[i].code )
      {
        msg += MorseMap[i].letter;
      }
    }

    lastPos = pos+1;
    pos = morse.indexOf(' ', lastPos);

    // Handle white-spaces between words (7 spaces)
    while( morse[lastPos] == ' ' &amp;&amp; morse[pos+1] == ' ' )
    {
      pos ++;
    }
  }

  return msg;
}
Anuncios