/* Project: 3x3x3 Mono LED Cube (r3). * File: MVRain.cpp * Description: * Movie -- mv_Rain * A number of LEDs are lit on the top plane, and they * then "fall down" the cude. * * 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" class Drop { public: byte pos; byte count; unsigned long time; byte spd; void reset() { pos = POS(2, random(0, 3), random(0, 3)); count = 2; spd = random(30, 100); time = millis() + spd; } void displayDrop(boolean state) { displayFrame[pos] = state ? MAXBRIGHTNESSLEVEL : 0; } void drop() { if (millis() > time) { if (spd == 0) { reset(); displayDrop(true); } else { displayDrop(false); if (count == 0) { spd = 0; time = millis() + random(50, 100); } else { --count; pos -= 3; displayDrop(true); time = millis() + spd; } } } } }; void mv_Rain() { unsigned long ts; byte y; Drop drops[2]; ts = millis() + (DEF_MOVIE_TIME * 2); for (y = 0 ; y < 2 ; y++) { drops[y].reset(); drops[y].displayDrop(true); } while (millis() < ts) { for (y = 0 ; y < 2 ; y++) { drops[y].drop(); } } df_clear(); }
Recent Comments