Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sketch of an arduino version of txtzyme

  • Loading branch information...
commit 4c8436482d4aee09b153e5650fe1b9924728876c 1 parent 4fb350d
@WardCunningham authored
Showing with 102 additions and 0 deletions.
  1. +102 −0 arduino/Arduinozyme/Arduinozyme.pde
View
102 arduino/Arduinozyme/Arduinozyme.pde
@@ -0,0 +1,102 @@
+
+unsigned int x = 0;
+int d = 13;
+
+void setup() {
+ Serial.begin(9600);
+}
+
+void loop() {
+ char buf[64];
+ txtRead(buf, 64);
+ txtEval(buf);
+}
+
+void txtRead (char *p, byte n) {
+ byte i = 0;
+ while (i < (n-1)) {
+ while (!Serial.available());
+ char ch = Serial.read();
+ if (ch == '\r' || ch == '\n') break;
+ if (ch >= ' ' && ch <= '~') {
+ *p++ = ch;
+ i++;
+ }
+ }
+ *p = 0;
+}
+
+void txtEval (char *buf) {
+ unsigned int k = 0;
+ char *loop;
+ char ch;
+ while ((ch = *buf++)) {
+ switch (ch) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ x = ch - '0';
+ while (*buf >= '0' && *buf <= '9') {
+ x = x*10 + (*buf++ - '0');
+ }
+ break;
+ case 'p':
+ Serial.println(x);
+ break;
+ case 'd':
+ d = x;
+ break;
+ case 'i':
+ x = digitalRead(d);
+ break;
+ case 'o':
+ digitalWrite(d, x%2);
+ break;
+ case 'm':
+ delay(x);
+ break;
+ case 'u':
+ delayMicroseconds(x);
+ break;
+ case '{':
+ k = x;
+ loop = buf;
+ while ((ch = *buf++) && ch != '}') {
+ }
+ case '}':
+ if (k) {
+ k--;
+ buf = loop;
+ }
+ break;
+ case 'k':
+ x = k;
+ break;
+ case '_':
+ while ((ch = *buf++) && ch != '_') {
+ Serial.print(ch);
+ }
+ Serial.println();
+ break;
+ case 's':
+ x = analogRead(x);
+ break;
+ }
+ }
+}
+
+
+
+
+
+
+
+
+

0 comments on commit 4c84364

Please sign in to comment.
Something went wrong with that request. Please try again.