Arduino: สร้างนักแปลมอร์ส - มันทำงานอย่างไร
ในเคล็ดลับที่ใช้งานได้จริงนี้คุณจะได้เรียนรู้วิธีสร้างตัวแปล Morse ด้วย Arduino ของคุณได้อย่างง่ายดาย
การสร้างนักแปลมอร์สด้วย Arduino - นี่เป็นสิ่งจำเป็น
ก่อนอื่นคุณต้องมี Arduino
- คุณควรได้รับเสียงสัญญาณเตือนที่ใช้งานและไฟ LED
- เชื่อมต่อกริ่งเพื่อ pin 9 และ LED เพื่อ pin 13
Arduino: โปรแกรมนักแปลมอร์ส
ที่นี่เราได้ตั้งโปรแกรมโค้ดตัวอย่างขนาดเล็กสำหรับคุณซึ่งคุณสามารถใช้ได้ เพียงอัปโหลดไปยัง Arduino และเริ่มตรวจสอบพอร์ตอนุกรม
- #define debug จริง
- int ledPin = 13;
- int speakerPin = 9;
- int pitch1 = 140;
- int pitch2 = 140;
- int dot = 50;
- int dash = 3 * dot;
- สตริง morseATable [] = {".-", "-... ", "-.-.", "- .. ", ".", ".. ", ".. ". ", " -. ", " ... ", " .. ", " .--- ", " _._ ", " .- .. ", " - ", " - ", " --- ", " --- ", - . ", " --.- ", " .-. ", " ... ", " - ", " ..- ", " ... - ", " ... ", " .-- ", " -..- " ", " -.-- ", " - .. "};
- String morseNTable [] = {"-----", ".----", "..---", "... -", ".... -", ".... -", "... .. ", " -.... ", " --... ", " --- .. ", " ----. "};
- การตั้งค่าเป็นโมฆะ () {
- pinMode (ledPin, OUTPUT);
- pinMode (speakerPin, OUTPUT);
- Serial.begin (9600);
- if (debug) {
- Serial.println ( "\ n เริ่ม");}
- }
- void loop () {
- ถ้า (จริง) {
- convert2Morse (Serial.readString ());
- }
- }
- เป็นโมฆะ convert2Morse (ข้อความ String) {
- สำหรับ (int pos = 0; pos <message.length (); pos ++) {
- if (debug) {
- Serial.print (message.charAt (POS));
- Serial.print ("");
- }
- ถ้า ((message.charAt (pos)> = 97) && (message.charAt (pos) <= 122)) {
- morseLED (morseATable [message.charAt (POS) -97]);}
- ถ้า ((message.charAt (pos)> = 48) && (message.charAt (pos) <= 57)) {
- morseLED (ตารางมอร์ส [ข้อความ [POS] -48]);}
- if (message.charAt (pos) == 32) {
- morseLED ("");}
- if (debug) {
- Serial.println ();
- }
- }}
- โมฆะ morseLED (ลำดับ String) {
- สำหรับ (int pos = 0; pos <sequence.length (); pos ++) {
- FlashLED (sequence.charAt (POS));}
- ล่าช้า (2 * จุด);
- }
- ถือเป็นโมฆะ flashLED (ถ่าน dotOrDash) {
- if (debug) {
- Serial.print (dotOrDash);}
- if (dotOrDash == 46) {
- digitalWrite (ledPin, HIGH);
- โทน (speakerPin, pitch1);
- ล่าช้า (dot);
- digitalWrite (ledPin, LOW);
- noTone (speakerPin);
- ล่าช้า (dot);
- } else if (dotOrDash == 45) {
- digitalWrite (ledPin, HIGH);
- โทน (speakerPin, pitch2);
- ล่าช้า (รีบ);
- digitalWrite (ledPin, LOW);
- noTone (speakerPin);
- ล่าช้า (dot);
- } else if (dotOrDash == 32) {
- ล่าช้า (dot);}
- }
ในเคล็ดลับการปฏิบัติถัดไปเราจะแสดงให้คุณเห็นว่าคุณสามารถใช้โมดูล GSM ใน Arduino ได้อย่างไร