상명대학교, 임베디드시스템

Dependencies:   ESP-call

Files at this revision

API Documentation at this revision

Comitter:
dshin
Date:
Mon May 23 05:22:16 2022 +0000
Commit message:
lab07-simple-timer

Changed in this revision

ESP-call.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
simple-timer.lua Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ESP-call.lib	Mon May 23 05:22:16 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/dshin/code/ESP-call/#11487122965a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 23 05:22:16 2022 +0000
@@ -0,0 +1,70 @@
+// ======================================================================
+
+#include "mbed.h"
+#include "ESP-call.h"
+
+// ======================================================================
+// NodeMCU program
+
+NodeMCU_PGM simple_timer[] = {
+    "", 1,
+    "delayms = 500", 1,
+    "", 1,
+    "LEDpin = 4", 1,
+    "LEDstate = 0", 1,
+    "", 1,
+    "gpio.mode(LEDpin,gpio.OUTPUT)", 1,
+    "", 1,
+    "function toggle()", 1,
+    "  if (LEDstate) then gpio.write(LEDpin,gpio.LOW)", 1,
+    "                else gpio.write(LEDpin,gpio.HIGH)", 1,
+    "  end", 1,
+    "  LEDstate = not LEDstate", 1,
+    "end", 1,
+    "", 1,
+    "mytimer = tmr.create()", 1,
+    "mytimer:register(delayms, tmr.ALARM_AUTO, function () toggle() end)", 1,
+    "mytimer:start()", 1,
+    NULL, 0,       // last line should be NULL and 0
+};
+
+// ======================================================================
+// Main thread
+
+int main()
+{
+    int i;
+    char *p;
+
+    // Config baudrate of PC and ESP
+    PC.baud(115200);
+    ESP.baud(115200);
+
+    // Reset ESP
+    PC.printf("\r\nReset ESP...\r\n");
+    ESP_reset();
+
+    // Setup ESP noecho mode
+    PC.printf("Setup ESP noecho...\r\n");
+    ESP_noecho();
+
+    // Execute a NodeMCU program
+    PC.printf("Execute a NodeMCU program...\r\n");
+    ESP_call_multi(simple_timer);
+
+    // Setup ESP echo mode
+    PC.printf("\r\nSetup ESP echo...\r\n");
+    ESP_echo();
+
+    // Config ESP passthrough mode
+    PC.printf("ESP passthrough mode...\r\n");
+    PC.attach(&ISR_PC_to_ESP, Serial::RxIrq);
+    ESP.attach(&ISR_ESP_to_PC, Serial::RxIrq);
+
+    // Main thread sleeps
+    while(1) {
+        sleep();
+    }
+}
+
+// ======================================================================
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon May 23 05:22:16 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/armmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simple-timer.lua	Mon May 23 05:22:16 2022 +0000
@@ -0,0 +1,17 @@
+delayms = 500
+
+LEDpin = 4
+LEDstate = 0
+
+gpio.mode(LEDpin,gpio.OUTPUT)
+
+function toggle()
+  if (LEDstate) then gpio.write(LEDpin,gpio.LOW)
+                else gpio.write(LEDpin,gpio.HIGH)
+  end
+  LEDstate = not LEDstate
+end
+
+mytimer = tmr.create()
+mytimer:register(delayms, tmr.ALARM_AUTO, function () toggle() end)
+mytimer:start()
\ No newline at end of file