/* Project: 3x3x3 Mono LED Cube (r3). * File: MVLightning.cpp * Description: * Movie -- mv_Lightning * Dark clouds, and occasional flashes of lightning. * * Copyright (C) 2014 Marc Symonds * All rights reserved. * * This software may be used and redistribtued, 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" void mv_Lightning() { unsigned long ts, m; unsigned long tl, tf; byte i, p, y, z, mode, cnt; Light cloud[9]; Point l1, l2; y = 0; z = 0; for (i = 0 ; i < 9 ; i++) { p = POS(2, y, z); displayFrame[p] = random(1, 3); cloud[i].up = (displayFrame[p] < 2); cloud[i].t = millis() + random(250, 750); if (++y > 2) { y = 0; ++z; } } ts = millis() + (DEF_MOVIE_TIME * 3); tl = millis() + random(2000, 5000); mode = 0; y = 0; z = 0; i = 0; m = millis(); while (m < ts) { if (m > cloud[i].t) { p = POS(2, y, z); displayFrame[p] += (cloud[i].up ? 1 : -1); if (displayFrame[p] < 2) cloud[i].up = true; else if (displayFrame[p] > 1) cloud[i].up = false; cloud[i].t = m + random(250, 750); } if (mode > 0) { if (m > tf) { if (mode == 1) { displayFrame[l1.Pos()] = 7; displayFrame[l2.Pos()] = 7; mode = 2; } else { displayFrame[l1.Pos()] = 0; displayFrame[l2.Pos()] = 0; if (--cnt < 1) { mode = 0; tl = millis() + random(2000, 5000); } else mode = 1; } tf = m + 30; } } else if (m > tl) { l1.x = 1; l1.y = random(0, 3); l1.z = random(0, 3); l2.x = 0; do { l2.y = l1.y + random(0, 3) - 1; } while (l2.y > 2); do { l2.z = l1.z + random(0, 3) - 1; } while (l2.z > 2); mode = 1; cnt = random(5, 8); tf = m; } if (++y > 2) { y = 0; if (++z > 2) z = 0; } if (++i > 8) i = 0; m = millis(); } df_fadeOut(); }
Recent Comments