Kirja   |  Artikkelit   |  Keskustelu   |  Tiedostot   |  Galleria
Hyönteisrobotti, kampanja.

Yksinkertainen sähkötysohjelma

Tässä olisi sitten hyvin, hyvin yksinkertainen morsekoodi Arduinolle.

Toimintaperiaate

Ohjelmassa määritellään tietty sana tai muu kirjainyhdistelmä (tällä hetkellä siis koodattu suoraan ohjelmaan) jota tuo Arduino sitten vilkuttaa LEDillään.

Ohjelmasta löytyy perus setup ja loop funktioden lisäksi kolme minun kirjoittamaa funktiota, morse, morseLong ja morseShort.

setup() ja loop()

int ledPin = 13;                                        // LED connected to digital pin 13
char message[12] = "hello world";
int morseUnit = 300;                            // milliseconds

void setup()                                            // run once, when the sketch starts
{
        pinMode(ledPin, OUTPUT);                // sets the digital pin as output
}

void loop()                                                     // run over and over again
{
        for(int i = 0; i<12; i++)
        {
                morse(message[i]);
        }
}

Tässä ei mitään sen erikoisempaa. loop käy for loopin avulla merkkijonon läpi kirjain kirmaimelta ja sen mukaan kutsuu morse funktiota.

morseLong ja MorseShort

void morseLong(int count)
{
        for(int i=0; i<count; i++)
        {
                digitalWrite(ledPin, HIGH);
                delay((3*morseUnit));
                digitalWrite(ledPin, LOW);
                delay(morseUnit);
        }
}

void morseShort(int count)
{
        for(int i=0; i<count; i++)
        {
                digitalWrite(ledPin, HIGH);
                delay(morseUnit);
                digitalWrite(ledPin, LOW);
                delay(morseUnit);
        }
}

Kuten nimistä voi päätellä, morseShort vilkuttaa yhden lyhyen väläykseen ja morseLong yhden pitkän. Kansainvälisen sähkötyksen sääntöjen mukaan (kiitos Wikipedia), yksi pitkä merkki on kolmen lyhyen pituinen. morseUnit määrittelee merkkien sekä taukojen pituudet.

morse

void morse(char letter)
{
        if(letter=='a')
        {
                morseLong(1);
                morseShort(1);
        }
        else if(letter=='c')
        {
                morseLong(1);
                morseShort(1);
                morseLong(1);
                morseShort(1);
        }
        else if(letter=='d')
        {
                morseLong(1);
                morseShort(2);
        }
        else if(letter=='e')
        {
                morseLong(1);
        }
        else if(letter=='f')
        {
                morseShort(2);
                morseLong(1);
                morseShort(1);
        }
        else if(letter=='g')
        {
                morseLong(2);
                morseShort(1);
        }
        else if(letter=='h')
        {
                morseShort(4);
        }
        else if(letter=='i')
        {
                morseShort(2);
        }
        else if(letter=='j')
        {
                morseShort(1);
                morseLong(3);
        }
        else if(letter=='k')
        {
                morseLong(1);
                morseShort(1);
                morseLong(1);
        }
        else if(letter=='l')
        {
                morseShort(1);
                morseLong(1);
                morseShort(2);
        }
        else if(letter=='m')
        {
                morseLong(2);
        }
        else if(letter=='n')
        {
                morseLong(1);
                morseShort(1);
        }
        else if(letter=='o')
        {
                morseLong(3);
        }
        else if(letter=='p')
        {
                morseShort(1);
                morseLong(2);
                morseShort(1);
        }
        else if(letter=='q')
        {
                morseLong(2);
                morseShort(1);
                morseLong(1);
        }
        else if(letter=='r')
        {
                morseShort(1);
                morseLong(1);
                morseShort(1);
        }
        else if(letter=='s')
        {
                morseShort(3);
        }
        else if(letter=='t')
        {
                morseLong(1);
        }
        else if(letter=='u')
        {
                morseShort(2);
                morseLong(1);
        }
        else if(letter=='v')
        {
                morseShort(3);
                morseLong(1);
        }
        else if(letter=='w')
        {
                morseShort(1);
                morseLong(2);
        }
        else if(letter=='x')
        {
                morseLong(1);
                morseShort(2);
                morseLong(1);
        }
        else if(letter=='y')
        {
                morseLong(1);
                morseShort(1);
                morseLong(2);
        }
        else if(letter=='z')
        {
                morseLong(2);
                morseShort(2);
        }
        else if(letter==' ')
        {
                digitalWrite(ledPin, LOW);
                delay((7*morseUnit));
        }
        delay((morseUnit*3));
}

Kaikessa yksinkertaisuudessaan morse funktio vilkuttaa sille syötetyn merkin mukaan oikean kirjaimen.

Toivottavasti joku saa jotain selkoa näistä minun selityksistä, kovin hyvä en ole selittämään. Varsinkaan suomeksi.

Admin edit: lyhennetty otsikko pois ingressistä, korotettu etusivulle

AttachmentSize
Morse.pde_.txt3.22 KB
0
  |     |  

Comments

What you need to do is to

What you need to do is to write the receiver code for what is called a USART (universal software receiver/transmitter). A USART is just a UART that's implemented in software. So you need to read up on how a UART receiver works. 640-721 Clue: No established UART speeds are within 6.25% (=1/16) of each other. Basically, the receiver must sample the incoming signal at 16 times the bit rate. In your case, the bit rate is one over the duration of a Morse dot. So if your dot lasts 200 ms (5 Hz), you must sample eighty times a second. JN0-201 With that sampling rate, the receiver can reliably determine on/off transitions even with slightly noisy input. It's somewhat like debouncing a mechanical switch. 642-586 If the receiver can sample at higher rates, a little cleverness can also allow it to determine the baud rate by measuring the duration of an incoming start bit.

Miksi suoraan

Miksi suoraan web-sovelluksesta ei käytetä sarjaporttia ja komenneta arduinoa? Gucci bags Tähän on oikeastaan pari syytä. Ensinnäkin projektin on tarkoituksena joskus kehittyä,tiffany jewellery niin että siitä voitaisiin hallita useampia kameroita, jotka eivät välttämättä ole edes samalla koneella tai samassa verkossa. Toisekseen projektin edetässä huomattiin,tiffany jewelry että ainakin tomcat varaa sarjaportit niin, että niitä ei voitu suoraan käyttää.

Post new comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Every instance heading tags will be modified to include an id attribute for anchor linking.
  • Every instance of "<!--tableofcontents-->" in the input text will be replaced with a collapsible mediawiki-style table of contents. Accepts options for title, list style, minimum heading level, and maximum heading level as follows: <!--tableofcontents list: ol; title: Table of Contents; minlevel: 1; maxlevel: 3;-->. All arguments are optional and defaults are shown.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Image links from G2 are formatted for use with Lightbox2
  • Image links with 'rel="lightshow"' in the <a> tag will appear in a Lightbox slideshow when clicked on.
  • Links to video content with 'rel="lightvideo"' in the <a> tag will appear in a Lightbox when clicked on.
  • Links to inline or modal content with 'rel="lightmodal"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.
(Round corners at the bottom)