/* Project: 3x3x3 Mono LED Cube (r3). * File: MVCounter.cpp * Description: * Movie -- mv_Counter * LED on bottom plane moves around the edge of the * plane. On each complete circuit, the LED on the * plane above moves along one, and when that has done * a complete circuit, the led on the top plane moves * along one. * * Copyright (C) 2014 Marc Symonds * All rights reserved. * * This software may be used and redistributed, with or without * modification, as long as it is understood that this software * is provided as-is without any explicit or implied warranties * of merchantablity or fitness of purpose. */ #include "Arduino.h" #include "Movies.h" #include "DisplayFrame.h" struct Item { public: byte x; byte d; Item() : x(0), d(0) {}; boolean inc() { boolean o = false; switch(d) { case 0: if (++x == 2) d = 1; break; case 1: x += 9; if (x > 18) d = 2; break; case 2: if (--x == 18) d = 3; break; case 3: x -= 9; if (x < 9) { d = 0; o = true; } break; } return o; } }; void mv_Counter() { Item i[3]; unsigned long ts, t; boolean o; int del; i[0].x = 0; i[1].x = 0; i[2].x = 0; displayFrame[i[0].x] = 7; displayFrame[i[1].x + 3] = 7; displayFrame[i[2].x + 6] = 7; delay(1000); del = random(20, 70); ts = millis() + (DEF_MOVIE_TIME * 2); while (millis() < ts) { t = millis() + del; displayFrame[i[0].x] = 0; o = i[0].inc(); displayFrame[i[0].x] = 7; if (o) { displayFrame[i[1].x + 3] = 0; o = i[1].inc(); displayFrame[i[1].x + 3] = 7; if (o) { displayFrame[i[2].x + 6] = 0; i[2].inc(); displayFrame[i[2].x + 6] = 7; } } while (millis() < t) ; } df_fadeOut(); delay(500); }
Recent Comments