Arduino-FVM
Byte Token Threaded Forth Virtual Machine (FVM) for Arduino
MultiBlink.ino
Go to the documentation of this file.
1 
28 #include <FVM.h>
29 
30 // Define to allow trace of virtual machine
31 #define USE_TRACE
32 
33 // 1 constant OUTPUT
34 FVM_CONSTANT(0, OUTPUT_MODE, "OUTPUT", 1);
35 
36 // : blink ( ms pin -- )
37 // OUTPUT over pinmode
38 // begin
39 // dup digitaltoggle
40 // over delay
41 // again ;
42 FVM_COLON(1, BLINK, "blink")
43  FVM_CALL(OUTPUT_MODE),
44  FVM_OP(OVER),
45  FVM_OP(PINMODE),
46  FVM_OP(DUP),
47  FVM_OP(DIGITALTOGGLE),
48  FVM_OP(OVER),
49  FVM_OP(DELAY),
50  FVM_OP(BRANCH), -5,
51  FVM_OP(EXIT)
52 };
53 
54 const FVM::code_P FVM::fntab[] PROGMEM = {
55  (code_P) &OUTPUT_MODE_CONST,
56  BLINK_CODE
57 };
58 
59 const str_P FVM::fnstr[] PROGMEM = {
60  (str_P) OUTPUT_MODE_PSTR,
61  (str_P) BLINK_PSTR,
62  0
63 };
64 
65 FVM::Task<16,8> task1(Serial);
66 FVM::Task<16,8> task2(Serial);
68 
69 void setup()
70 {
71  Serial.begin(57600);
72  while (!Serial);
73 
74 #if defined(USE_TRACE)
75  task1.trace(true);
76  task2.trace(true);
77 #endif
78 
79  // 500 13 blink
80  task1.push(500);
81  task1.push(13);
82  fvm.execute(BLINK_CODE, task1);
83 
84  // 100 12 blink
85  task2.push(100);
86  task2.push(12);
87  fvm.execute(BLINK_CODE, task2);
88 }
89 
90 void loop()
91 {
92  fvm.resume(task1);
93  fvm.resume(task2);
94 }
int resume(task_t &task)
Definition: FVM.cpp:143
Definition: FVM.h:339
const char * str_P
Definition: FVM.h:32
static const str_P fnstr[]
Definition: FVM.h:629
int execute(int op, task_t &task)
Definition: FVM.cpp:1837
#define FVM_COLON(id, var, name)
Definition: FVM.h:728
Definition: FVM.h:34