Dotstar LED demonstration, with stacker game. Uses 2 buttons, and LPC1768 microcontroller

Dependencies:   DotStar mbed

Committer:
pwalne
Date:
Wed Jan 04 20:55:18 2017 +0000
Revision:
1:37200a0da529
Parent:
0:9ab173ff6353
Working version with DotStar LED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pwalne 0:9ab173ff6353 1 #include "mbed.h"
pwalne 0:9ab173ff6353 2 #include "./DotStar/DotStar.h"
pwalne 0:9ab173ff6353 3 #include "./modes/light_show.h"
pwalne 0:9ab173ff6353 4 #include "./modes/stacker.h"
pwalne 0:9ab173ff6353 5 Serial pc(USBTX, USBRX);
pwalne 0:9ab173ff6353 6 InterruptIn btn1_(p8);
pwalne 0:9ab173ff6353 7 InterruptIn btn2_(p9);
pwalne 0:9ab173ff6353 8 Light_Game* mode = NULL;
pwalne 0:9ab173ff6353 9 void btn2Func() {
pwalne 0:9ab173ff6353 10 if(::mode == NULL) {
pwalne 0:9ab173ff6353 11 ::mode = new Light_Show();
pwalne 0:9ab173ff6353 12 return;
pwalne 0:9ab173ff6353 13 }
pwalne 0:9ab173ff6353 14 ::mode->btn1();
pwalne 0:9ab173ff6353 15 }
pwalne 0:9ab173ff6353 16 void btn1Func() {
pwalne 0:9ab173ff6353 17 if(::mode == NULL) {
pwalne 0:9ab173ff6353 18 ::mode = new Stacker();
pwalne 0:9ab173ff6353 19 wait(0.2); //wait for button to click or it will auto lose.
pwalne 0:9ab173ff6353 20 return;
pwalne 0:9ab173ff6353 21 }
pwalne 0:9ab173ff6353 22 ::mode->btn2();
pwalne 0:9ab173ff6353 23 }
pwalne 0:9ab173ff6353 24 int main() {
pwalne 0:9ab173ff6353 25 strip.begin();
pwalne 0:9ab173ff6353 26 strip.show();
pwalne 0:9ab173ff6353 27 btn1_.rise(&btn1Func);
pwalne 0:9ab173ff6353 28 btn2_.rise(&btn2Func);
pwalne 0:9ab173ff6353 29 wait(1);
pwalne 0:9ab173ff6353 30 while(1) {
pwalne 0:9ab173ff6353 31 pc.printf("Please enter a Light Option.\n");
pwalne 0:9ab173ff6353 32 pc.printf("\t0 - Normal light demonstration\n");
pwalne 0:9ab173ff6353 33 pc.printf("\t1 - Stacker game\n");
pwalne 0:9ab173ff6353 34 while(mode == NULL) {
pwalne 0:9ab173ff6353 35 if(!pc.readable()) continue;
pwalne 0:9ab173ff6353 36 char raw = pc.getc(); //wait for their input!
pwalne 0:9ab173ff6353 37 int opt = raw - 48;
pwalne 0:9ab173ff6353 38 if(opt > 1) {
pwalne 0:9ab173ff6353 39 pc.printf("Invalid Option!");
pwalne 0:9ab173ff6353 40 continue;
pwalne 0:9ab173ff6353 41 }
pwalne 0:9ab173ff6353 42 switch(opt) {
pwalne 0:9ab173ff6353 43 case 1://Stacker game.
pwalne 0:9ab173ff6353 44 mode = new Stacker();
pwalne 0:9ab173ff6353 45 break;
pwalne 0:9ab173ff6353 46
pwalne 0:9ab173ff6353 47 default:
pwalne 0:9ab173ff6353 48 mode = new Light_Show();
pwalne 0:9ab173ff6353 49 }
pwalne 0:9ab173ff6353 50 }
pwalne 0:9ab173ff6353 51 mode->init();
pwalne 0:9ab173ff6353 52 while(!mode->isFinished()) {
pwalne 0:9ab173ff6353 53 mode->update();
pwalne 0:9ab173ff6353 54 if(pc.readable()) {
pwalne 0:9ab173ff6353 55 pc.getc();
pwalne 0:9ab173ff6353 56 break;
pwalne 0:9ab173ff6353 57 }
pwalne 0:9ab173ff6353 58 }
pwalne 0:9ab173ff6353 59 mode->end();
pwalne 0:9ab173ff6353 60 delete mode;
pwalne 0:9ab173ff6353 61 mode = NULL;
pwalne 0:9ab173ff6353 62 }
pwalne 0:9ab173ff6353 63 }