Test program to exercise the filagree library: http://mbed.org/users/yusufx/libraries/filagree

Dependencies:   mbed filagree

Committer:
yusufx
Date:
Wed May 30 21:14:32 2012 +0000
Revision:
0:23a8b3249249

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yusufx 0:23a8b3249249 1 #include "mbed.h"
yusufx 0:23a8b3249249 2 #include "vm.h"
yusufx 0:23a8b3249249 3 #include "compile.h"
yusufx 0:23a8b3249249 4 #include "interpret.h"
yusufx 0:23a8b3249249 5
yusufx 0:23a8b3249249 6 BusOut leds(LED1, LED2, LED3, LED4);
yusufx 0:23a8b3249249 7 Serial pc(USBTX, USBRX); // tx, rx
yusufx 0:23a8b3249249 8
yusufx 0:23a8b3249249 9 void callback(struct Context *context) {
yusufx 0:23a8b3249249 10 struct stack *stack = context->rhs;
yusufx 0:23a8b3249249 11 struct variable *f = (struct variable*)stack_pop(stack);
yusufx 0:23a8b3249249 12 const char *fstr = byte_array_to_string(f->str);
yusufx 0:23a8b3249249 13 struct variable *v = (struct variable*)stack_pop(stack);
yusufx 0:23a8b3249249 14
yusufx 0:23a8b3249249 15 if (!strcmp(fstr, "blink")) {
yusufx 0:23a8b3249249 16 pc.printf("blink %d\n\r", v->integer);
yusufx 0:23a8b3249249 17 leds = 1 << v->integer;
yusufx 0:23a8b3249249 18 } else if (!strcmp(fstr, "wait")) {
yusufx 0:23a8b3249249 19 pc.printf("wait %.1f\n\r", v->floater);
yusufx 0:23a8b3249249 20 wait(v->floater);
yusufx 0:23a8b3249249 21 }
yusufx 0:23a8b3249249 22 }
yusufx 0:23a8b3249249 23
yusufx 0:23a8b3249249 24 int main() {
yusufx 0:23a8b3249249 25 const char *fg = "b = 0 while b<40 vm.yield('blink',b%4) b = b+1 vm.yield('wait',0.5) end";
yusufx 0:23a8b3249249 26 interpret_string(fg, &callback);
yusufx 0:23a8b3249249 27 }