2020年9月

Arduino摩尔斯电码解码,原作者(Demented hacker)可能是荷兰藉,原代码为荷兰语变量,部分变量已修改为英语,增加了0-9数字编码

// (C) 2016 Demented hacker
// modify: osthink@gmail.com 2020
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// 引脚7连接按键并接GND
// 引脚8连接蜂鸣器并接GND
// 1802液晶使用引脚10、11(软串口)

#define KEY 7  //按键
#define BUZZER 8   // 蜂鸣器

unsigned char k = 0; //光标初始位置
SoftwareSerial softSerial(10, 11);//软串口设置
LiquidCrystal_I2C lcd(0x27, 16, 2);//I2C设备地址、列数,行数

//设置函数
void setup() {
  pinMode(KEY, INPUT_PULLUP);
  pinMode(BUZZER, OUTPUT);
  Serial.begin(115200);
  softSerial.begin(9600);
  softSerial.listen();
  lcd.init(); // 初始化LCD
  lcd.backlight(); //设置LCD背景灯亮
  lcd.setCursor(0, 0); //设置显示指针
  lcd.print("**MORSE-DECODE**"); //输出字符到LCD1602上   
}

//变量定义
float StreepDuur = 200.0;//剥离时间
boolean PrevS = false;
long tStartTeken, tStartPauze;
boolean S;
String kar = "";
boolean clearLcd = true;

//程序主循环
void loop() {
  S = !digitalRead(KEY);

  if (S) {
    if (S != PrevS) {
      tStartTeken = millis();
      DecodeerPauze(tStartPauze);
    }
    digitalWrite(BUZZER, HIGH);
  }
  else {
    if (S != PrevS) {
      tStartPauze = millis();
      Decodeer(tStartTeken);
    }
    digitalWrite(BUZZER, LOW);
  }

  if (abs(millis() - tStartPauze) > StreepDuur * 10) {
    DecodeerPauze(tStartPauze);
  }

  PrevS = S;
}


void Decodeer(long startTime) {
  char teken = '?';
  long keepTime = abs(millis() - startTime); // 信号的持续时间(点或划)
  float PuntDuur = StreepDuur / 3.0;

  if (keepTime <= 2) return; // Denderonderdrukking

  if (keepTime <= PuntDuur) teken = '.';
  else if (keepTime > StreepDuur) teken = '-';
  else if ((keepTime > (StreepDuur + PuntDuur) / 1.9) && keepTime <= StreepDuur) teken = '-';
  else teken = '.';

  if (teken == '-') {
    if (keepTime > StreepDuur) StreepDuur++;
    if (keepTime < StreepDuur) StreepDuur--;
  }
  else if (teken == '.') {
    if (keepTime > StreepDuur / 3.0) StreepDuur++;
    if (keepTime < StreepDuur / 3.0) StreepDuur--;
  }
  kar += teken;
  //Serial.println(teken);
}

void DecodeerPauze(long startTime) {
  if (kar == "") return;

  char teken = '?';
  long keepTime = abs(millis() - startTime);
  if (keepTime > StreepDuur - StreepDuur / 40) {
    DecodeerKar();
    //Serial.print();
  }
  if (keepTime > StreepDuur * 2) {
    DecodeerKar();
    Print(" "); Serial.print(" ");
  }
  //else DecodeerKar();
  //Serial.println(teken);
}

void DecodeerKar() {
  static String letters[] = {
    "-----",".----","..---","...--","....-",".....","-....","--...","---..","----."," "," "," "," "," "," "," ",".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-",
    ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "E"
  };
  int i = 0;
  while (letters[i] != "E") {
    if (letters[i] == kar) {
      Print((char)('0' + i));
      Serial.print((char)('A' + i));
      break;
    }
    i++;
  }
  if (letters[i] == "E") {
    Print(kar);
    Serial.print(kar);
  }
  kar = "";
}

int y = 0, x = 0;
void Print(String &s) {
  for (int i = 0; i < s.length(); i++) {
    upd(); lcd.print(s[i]);
  }
}
void Print(char s) {
  upd();
  lcd.print(s);
}
void Print(char *s) {
  for (int i = 0; i < strlen(s); i++) {
    upd();
    lcd.print(s[i]);
  }
}

void upd() {
  lcd.setCursor(x, y);
  if (clearLcd){
    lcd.clear();
    x=y = 0;
    clearLcd = false;   
  }
  x++; if (x >= 16) {
    x = 0;
    y++;
  }
  if (y >= 2) {
    lcd.clear();
    x=y = 0;    
  }
}

- 阅读剩余部分 -

配置:CPU奔腾1 MMX 200Hz 24m内存 dos7.1 /windows98系统,创新4330声卡。

体验56k moden拨号上网!

箱内置了单片机ARDUINO,机箱小屏是1602LCD,写了个Dos下的串口通信程序与ARDUINO通讯。

目前dos系统下可用的功能:
1、播放音乐
2、上网
3、看图
4、QB/C/C++编程
5、玩游戏(红色警戒、模拟城市2000等)
6、画图

☎️56k猫拨号上网(Windows98下,需要搭建拨号服务网络)

✈️业余无线电操作证到手啦,呼号:BH7EDY,欢迎各位前辈指导!







- 阅读剩余部分 -