/* Lazy8 - display running lights in a sideways figure eight Lazy8 0.0 Arduino Trixel example Copyright (c) 2011 Devon Sean McCullough Licensed under the GPL (GNU Public License) Requires the Trixel and LiquidCrystal libraries and a 10x2 or better LCD display with 5 or more characters of font RAM. */ #include #include // RS, Enable, D4, D5, D6, D7); LiquidCrystal lcd(11, 12, 4, 5, 6, 7); Trixel trix(&lcd); /* 10 x 6 trixel matrix (in 10 x 2 LCD) // (dotimes (y 6) (princ "\n ") (dotimes (x 10) (princ (format " %3d," (+ x (* y 10)))))) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 1, 2, 7, 8, 10, 13, 16, ++ 19, 20, 24, 25, ++ 29, 30, -- 34, 35, 39, 40, -- 43, 46, 49, 51, 52, 57, 58, */ const uint8_t path[] = { 1, 2, 13, 24, 35, 46, 57, 58, // down-right 49, 39, 29, 19, // up 8, 7, 16, 25, 34, 43, 52, 51, // down-left 40, 30, 20, 10 // up }; const uint8_t pattern[] = {1, 1, 1, 0, 0, 0, 0, 0}; #define SIZEOF_ARRAY(a) (sizeof(a)/sizeof(*(a))) int mod (int quotient, int divisor) { // A reasonable compiler would reduce this to a single machine instruction int remainder = quotient % divisor; if (remainder < 0) remainder += divisor; return remainder; } void setup() { lcd.begin(12, 2); // LCD columns and rows trix.begin(12, 2); // trixel buffer and LCD font RAM lcd.print("Lazy8 demo"); // show message on LCD delay(1000); // ... for one second } int phase = 0; void loop () { // running lights repeat pattern along path for (int i = 0; i < SIZEOF_ARRAY(path); i++) { int offset = mod(i - phase, SIZEOF_ARRAY(pattern)); uint8_t xy = path[i]; uint8_t x = xy % 10; uint8_t y = xy / 10; trixel_color color = (trixel_color)pattern[offset]; trix.setDot(x, y, color); } #if 1 // sketchy Arduino[tm] logo // with background - and foreground + if (!trix.getDot(2, 5)) trix.setChar(2, 5, '-'); trix.setChar(7, 0, '+'); #endif trix.show(); phase = mod(phase + 1, SIZEOF_ARRAY(path)); delay(100); }