Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions xmastree.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,31 @@
*
* We cannot provide any support for this code, but feel free to use it as a
*/
#include <EasyButton.h>
#include <dmtimer.h>
#include <FastLED.h>
#define BUTTON_ONE_LED_PIN 14// 9//right
#define BUTTON_TWO_LED_PIN 15// 11 //left
#define BUTTON_ONE_PIN 16 //10 //left
#define BUTTON_TWO_PIN 17// 12//right
EasyButton button1(BUTTON_ONE_PIN);
EasyButton button2(BUTTON_TWO_PIN);
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
//setup constants and variables for gameplay
const int initGameSpeed = 500;
const bool renderGameAsText = false;
#define NUM_STRIPS 10
#define NUM_LEDS_PER_STRIP 50
bool screenSaverToggle = false;
int screenSaverTimeOut = 0;
//define gameboard matrix
const int rows = NUM_LEDS_PER_STRIP;
const int columns = NUM_STRIPS;
int gameArray[columns][rows];
CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];
bool queueNewGame = false;
bool gameOn = false;
int screenSaverSelector = 1;
Expand All @@ -55,11 +45,9 @@ int waitForDropIncrease = 0;
int waitForDropThreshold = 5;
int increaseDropThreshold = 35;
DMTimer myTimer(initGameSpeed);
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
currentPalette = CloudColors_p;
currentBlending = LINEARBLEND;

Expand All @@ -79,7 +67,6 @@ digitalWrite(BUTTON_TWO_LED_PIN, HIGH);
FastLED.addLeds<WS2811, 9>(leds[6], NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2811, 10>(leds[6], NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2811, 11>(leds[6], NUM_LEDS_PER_STRIP);
// Initialize the button1
button1.begin();
// Initialize the button2
Expand All @@ -90,14 +77,11 @@ digitalWrite(BUTTON_TWO_LED_PIN, HIGH);
button2.onPressed(onButton2Pressed);
Serial.println("Ready......");
}
void loop() {
if(myTimer.isTimeReached()){ //check if execution time has been reached
tickTock();
}
}
void onButton1Pressed() {
if(queueNewGame == false){
if(gameOn == true){
Expand All @@ -112,7 +96,6 @@ void onButton1Pressed() {
}
}
}
void onButton2Pressed() {
if(queueNewGame == false){
if(gameOn == true){
Expand All @@ -127,14 +110,12 @@ void onButton2Pressed() {
}
}
}
void tickTock(){
button1.read();
button2.read();
if(queueNewGame == true){
startNewGame();
}
switch(gameOn){
case false:
//screensaver mode
Expand All @@ -158,7 +139,6 @@ waitForDrop = 0;
waitForDropIncrease = 0;
waitForDropThreshold = 5;
increaseDropThreshold = 35;
//clear gameboard
for (int i = columns-1; i >=0; i--) {
for (int j = rows-1; j >= 0; j--) {
Expand All @@ -170,15 +150,12 @@ increaseDropThreshold = 35;
gameOn = true;
queueNewGame = false;
}
void stepGame(){
//Serial.println("stepGame");
countUntilDrop--;
if(countUntilDrop <= 0){
dropPiece();
}
for (int i = columns-1; i >=0; i--) {
for (int j = rows-1; j >=0; j--) {
int locValue = gameArray[i][j];
Expand Down Expand Up @@ -238,7 +215,6 @@ void stepGame(){
leds[i][NUM_LEDS_PER_STRIP-j] = CRGB::Black;
break;
}
//check for player collision
if(j == rows-1){
if(gameArray[i][j]==1){
Expand All @@ -249,7 +225,6 @@ void stepGame(){
}
//Serial.println("tick complete");
}
void renderGameBoard() {
if(renderGameAsText == false){
//Serial.println("renderGameBoard");
Expand Down Expand Up @@ -312,15 +287,13 @@ void stepScreensaver() {
}
}
}
void checkCollision(int k) {
if(playerX == k){
//Collision found
gameOn = false;
playLoseAnim();
}
}
void dropPiece() {
// set random top row location
countUntilDrop = levelStepper;
Expand All @@ -343,7 +316,6 @@ void dropPiece() {
gameArray[ranX][0] = 1;
}
}
void playLoseAnim() {

for(int k = 0; k < 3; k++) {
Expand Down