Pages: [1]   Go Down
Author Topic: cant work out code  (Read 733 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
I am using this code
Code:
/*
               MORSE ENDECODER

  Morse encoder / decoder classes for the Arduino.


  This example decodes Morse signals present on digital input 7.
  (active low, and then also using the internal pullup resistor)

  It also encodes Morse sent via the serial interface to the Arduino, on
  digital output pin 13.
  
  It can also decode audible signals, if using the constant MORSE_AUDIO
  instead of MORSE_KEYER, but then it is important to note that the
  input pin nr. will be for ANALOG inputs (0-5 on Atmega 168 - 328),
  and not the digital inputs.



  Copyright (C) 2010 raron
  
 
*/


#include <MorseEnDecoder.h>


int morseInPin = 4;      
int morseOutPin = 6;
int x = 0;
int y = 0;


morseDecoder morseInput(morseInPin, MORSE_KEYER, MORSE_ACTIVE_LOW);
morseEncoder morseOutput(morseOutPin);

#include <LiquidCrystal.h>                  //include lcd library

LiquidCrystal lcd(11, 12, 7, 8, 9,10);


void setup()
{

  lcd.begin(16, 2);
  Serial.begin(9600);
  Serial.println("Morse EnDecoder demo");
  
  // Setting Morse speed in wpm - words per minute
  // If not set, 13 wpm is default
  morseInput.setspeed(40);
  morseOutput.setspeed(40);
}



void loop()
{
  // Needs to call these once per loop
  
  morseInput.decode();
  morseOutput.encode();

  // Morse output:
  // Encoding text received from the serial input
  if (Serial.available() && morseOutput.available())
  {
    
    
    char sendMorse = Serial.read();
    morseOutput.write(sendMorse);
    //String code=Serial.read();
    
    if(x  <=15){
    // Also write it back to serial
    morseOutput.encode();    // This is just to get morseSignalString before it is destroyed
    Serial.write(' ');
    Serial.write(sendMorse);
    //Serial.write(morseOutput.morseSignalString);
    lcd.setCursor(x,0);
    lcd.print (sendMorse);
    //lcd.setCursor(1,1);
    //lcd.print(x);
    x=x++;
    }
    
            if(x>=16){
             char sendMorse = Serial.read();
              morseOutput.write(sendMorse);
    
                // Also write it back to serial
                morseOutput.encode();    // This is just to get morseSignalString before it is destroyed
                Serial.write(' ');
                Serial.write(sendMorse);
                //Serial.write(morseOutput.morseSignalString);
                lcd.setCursor(y,1);
                lcd.print (sendMorse);
                //lcd.setCursor(0,0);
                //lcd.print(y);
                y=y++;
                      if((x>=16) && (y >=16)){
                      x=0;
                      y=0;
                      }
 }
}
  // Morse input:
  // If a character is decoded from the input, write it to serial output
  if (morseInput.available())
  {
    char receivedMorse = morseInput.read();
    Serial.print(receivedMorse);
    
    // A little error checking    
    if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
  }


  // Morse feedback from input if not sending Morse.
  if (morseOutput.available()) digitalWrite(morseOutPin, morseInput.morseSignalState);
}


the library it calls looks like this
Code:
#ifndef MorseEnDecoder_H
#define MorseEnDecoder_H

#if (ARDUINO <  100)
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

#define MORSE_AUDIO true
#define MORSE_KEYER false
#define MORSE_ACTIVE_LOW true
#define MORSE_ACTIVE_HIGH false


class morseDecoder
{
  public:
    morseDecoder(int decodePin, boolean listenAudio, boolean morsePullup);
    void decode();
    void setspeed(int value);
    char read();
    boolean available();
    int AudioThreshold;
    long debounceDelay;     // the debounce time. Keep well below dotTime!!
    boolean morseSignalState;  
  private:
    int morseInPin;         // The Morse input pin
    int audioSignal;
    int morseTableJumper;
    int morseTablePointer;
    int wpm;                // Word-per-minute speed
    long dotTime;           // morse dot time length in ms
    long dashTime;
    long wordSpace;
    boolean morseSpace;     // Flag to prevent multiple received spaces
    boolean gotLastSig;     // Flag that the last received morse signal is decoded as dot or dash
    boolean morseKeyer;
    boolean lastKeyerState;
    boolean morseAudio;
    boolean activeLow;
    long markTime;          // timers for mark and space in morse signal
    long spaceTime;         // E=MC^2 ;p
    long lastDebounceTime;  // the last time the input pin was toggled
    long currentTime;       // The current (signed) time
    char decodedMorseChar;  // The last decoded Morse character
};




class morseEncoder
{
  public:
    morseEncoder(int encodePin);
    void encode();
    void setspeed(int value);
    void write(char temp);
    boolean available();
    char morseSignalString[7];// Morse signal for one character as temporary ASCII string of dots and dashes
  private:
    char encodeMorseChar;   // ASCII character to encode
    int morseOutPin;
    boolean sendingMorse;
    int wpm;                // Word-per-minute speed
    long dotTime;           // morse dot time length in ms
    long dashTime;
    long wordSpace;
    int morseSignals;       // nr of morse signals to send in one morse character
    int morseSignalPos;
    int sendingMorseSignalNr;
    long sendMorseTimer;
    long lastDebounceTime;
    long currentTime;
};


#endif



in the guys demo of the code he has a buzzer and LED connected to the morse output , which buzz and light according to the morse code,
my buzzer doesnt have an internal tone generator,

I am hoping to use the tone() function
like this,
tone(6,4000);
to create a tone on the buzzer at the same time that the led lights, but i cant for the life of me find the part of code that lights the led,

i then assume that i would need a noTone(6) to stop it in the relevant place aswell, but im stumped,

any ideas?
« Last Edit: June 26, 2012, 08:58:24 am by spruce_m00se » Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 31
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There should be a file MorseEnDecoder.cpp that contains the actual class code (you just posted the header file for the library).  I would look in either the encode or write methods of the Encoder class.  Seach for

morseEncoder::encode or morseEncoder::write
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it wont let me post the otehr file you mention ,

but i looked in it and tried including the tone() after i saw the pin 6 put HIGH and notone() when its put low, but it didnt do the job ,

i will look a bit more later
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 31
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a limit to how long the text of a post can be, which is why it likely didn't let you post the other file.  In those situations you can attach the files, including images, etc. using the Additional Options drop down when you enter messages.
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okay, here it is

* MorseEnDecoder.cpp (12.12 KB - downloaded 27 times.)
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i opened it in wordpad, added the code where i think i need it and saved it, so lets see what happens,

i think the reason it may have not worked last time is because i edited the copy on the usb drive by mistake, not the copy in the libraries folder for arduino
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well,

there is some positive change and some negative change that has been made,

the positive is that the code now works and produces the tone for the first 16 characters.

the negative is that now, when the character length goes over 16 it starts to drop characters ,

my modifications to the code make it drop the cursor to the bottom line when x(the character count) reaches 16, then it increments y(the bottom line cahracter count) with each character printed,

im guessing that this isnt the cause as it works well without the beeping function, but when beeping is added it doesnt,

so i have two options,
1)limit messages to 16 characters,
2) sort it out,

Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wheey

sorted, apparently a small difference between the code under the conditions for the first line and second makes a big difference when the beeps are added,

so although it wasnt a problem without beeps it had to be changed,

now i have a good beeping board that prints the text out to serial and lcd,

it does get a bit confused with long strings though, especially when they are all very similar morse codes, and it seems to get out of sync with the serial every now and then as a result,

now to take the buzzer output and put it on a mic input and see if it comes out of speakers,
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so far so good,

the morse code is transmitted to the other walkie talkie and comes out of the speaker,

now time to replicate the arduino and see if the recevier walkie talkie can decode what it receives,

its going well,

for anyone interested, i made a basic attenuation circuit between the tone() pin and ground and the mic input and ground, using some old resistors out of a power supply, (result!!)
Logged

Pages: [1]   Go Up
Jump to: