处理适应问题的莫尔斯电码解码器 [英] Morse Code Decoder on Processing Adaptation Problem

查看:24
本文介绍了处理适应问题的莫尔斯电码解码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对处理进行莫尔斯电码解码器.我有 Arduino 代码,但我想在没有任何物理仪器或其他按钮的情况下完成它,只使用我的电脑和鼠标点击.

I'm trying to do Morse Code Decoder on Processing. I'm having Arduino codes for it, but I want to do it without any physical instrument or another button, only using my computer and a mouse click.

这是我用于 Arduino 的链接.

Here is the link for that I used for Arduino.

我正在尝试将我在互联网上找到的 Arduino 代码优化为处理,但我对处理没有任何专业知识.

I'm trying to optimize the Arduino code that I found on the internet, to the Processing but not having any expertise on Processing.

/*
  PROGRAM TO DECIPHER MORSE CODE USING A PUSH BUTTON AND DISPLAY IT ON THE SERIAL MONITOR
  DATE: 20 JANUARY 2017
  AUTHORS: PINAKI SADHUKHAN AND PRIYANKA SADHUKHAN
*/

unsigned long signal_len,t1,t2;   //time for which button is pressed
int inputPin = 2;                 //input pin for push button
int ledPin = 4;                   //outpu pin for LED
String code = "";                 //string in which one alphabet is stored

void setup() {
  Serial.begin(9600);
  pinMode(inputPin, INPUT_PULLUP); //internal pullup resistor is used to simplify the circuit
  pinMode(ledPin,OUTPUT);
}

void loop()
{
NextDotDash:
  while (digitalRead(inputPin) == HIGH) {}
  t1 = millis();                            //time at button press
  digitalWrite(ledPin, HIGH);               //LED on while button pressed
  while (digitalRead(inputPin) == LOW) {}
  t2 = millis();                            //time at button release
  digitalWrite(ledPin, LOW);                //LED off on button release
  signal_len = t2 - t1;                     //time for which button is pressed
  if (signal_len > 50)                      //to account for switch debouncing
  {
    code += readio();                       //function to read dot or dash
  }
  while ((millis() - t2) < 500)           //if time between button press greater than 0.5sec, skip loop and go to next alphabet
  {     
    if (digitalRead(inputPin) == LOW)
    {
      goto NextDotDash;
    }
  }
  convertor();                          //function to decipher code into alphabet
}

char readio()
{
  if (signal_len < 600 && signal_len > 50)
  {
    return '.';                        //if button press less than 0.6sec, it is a dot
  }
  else if (signal_len > 600)
  {
    return '-';                        //if button press more than 0.6sec, it is a dash
  }
}

void convertor()
{
  static String letters[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-",
                             ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "E"
                            };
  int i = 0;
  if (code == ".-.-.-")
  {
    Serial.print(".");        //for break
  }
  else
  {
    while (letters[i] != "E")  //loop for comparing input code with letters array
    {
      if (letters[i] == code)
      {
        Serial.print(char('A' + i));
        break;
      }
      i++;
    }
    if (letters[i] == "E")
    {
      Serial.println("<Wrong input>");  //if input code doesn't match any letter, error
    }
  }
  code = "";                            //reset code to blank string
}

我正在尝试使其适应 Processing3,但是,许多代码与 Processing 不兼容,而不是它们都使用 Java 语言.我所有的挣扎都是徒劳的.

I'm trying to adapt it to Processing3 but, many of the codes do not have compatibility with Processing, instead of both of them using Java language. All of my struggles are in vain.

推荐答案

我不是 100% 你想知道的,但我猜你想在 Processing 中实现一个莫尔斯解码器,你所拥有的只是一个 Arduino 实现.

I'm not 100% what you want to know but I guess you want to implement a morse decoder in Processing and all you have is an Arduino implementation.

与其尝试翻译 Arduino 实现(如果您能阅读 Arduino 代码,这不是一个坏主意),何不简单地从头开始实现它.

So rather than trying to translate an Arduino implementation (which is not a bad idea if you can read Arduino code) why not simply implement it from scratch.

如果您想使用鼠标,以下是您需要知道的:

Here's what you need to know, if you want to use your mouse:

  • 如何处理鼠标按钮的按下和释放
  • 如何测量时间
  • 您要解码的特定莫尔斯电码的时间
  • 如何输出一些文本
  • 一些基本的处理知识,以便您可以使用变量和控制结构

这些知识可以通过网络搜索快速获得.

This knowledge can quickly be obtained through websearch.

然后您测量鼠标每次按下时按下的时间.这给你.和 _ 然后你将它们组合成给你单词的字符.

Then you measure how long the mouse is pressed down each time it is pressed down. This gives you . and _ which you then combine to characters which give you words.

这篇关于处理适应问题的莫尔斯电码解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆