Skip to content

Commit

Permalink
Example of add animation: PACMAN
Browse files Browse the repository at this point in the history
  • Loading branch information
jellewie committed Oct 14, 2020
1 parent 181a875 commit 82d5a39
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
35 changes: 34 additions & 1 deletion Arduino/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Arduino.ino: Add the caller to 'switch (Mode) {' as a new case 'case ###: if (LastMode != Mode) StartAnimation(xxx, -2); break;'. where ### is the enum name and xxx ths ID in the 'switch (CurrentAnimation)'
*/
byte CurrentAnimation; //Which AnimationCounter Animation is selected
byte TotalAnimations = 11;
byte TotalAnimations = 12;
CRGB AnimationRGB = {0, 0, 0};

//==================================================
Expand Down Expand Up @@ -305,7 +305,40 @@ void ShowAnimation(bool Start) { //This would be called to show an Animati
UpdateLEDs = true;
}
} break;
case 12: { //PACMAN

//TODO maybe add a rare female PACMAN

#define PacmanMouthOpen 16
#define PacmanMouthOpenhalf PacmanMouthOpen / 2
#define PacmanStartT 15 - PacmanMouthOpenhalf
#define PacmanStartB 15
static byte _Counter, _Counter2;
static bool _Direcion, _Direcion2, _LeftMouth;
if (Start) {
_LeftMouth = random8(0, 2);
_Counter = 0;
_Counter2 = 0;
_Direcion = false;
_Direcion2 = false;
LED_Fill(0, TotalLEDs, CRGB(255, 255, 0));
if (_LeftMouth)
LED_Fill(60 - LEDtoPosition(PacmanStartT - 1), 2, CRGB(0, 0, 0)); //Cut out the eye
else
LED_Fill(LEDtoPosition(PacmanStartT - 4), 2, CRGB(0, 0, 0)); //Cut out the eye
UpdateLEDs = true;
}
EVERY_N_MILLISECONDS(25) {
if (_LeftMouth) {
LED_BackAndForth(60 - LEDtoPosition(PacmanStartT), PacmanMouthOpenhalf, CRGB(255, 255, 0), &_Counter, & _Direcion, false); //Upper lip
LED_BackAndForth(60 - LEDtoPosition(PacmanStartB), PacmanMouthOpenhalf, CRGB(255, 255, 0), &_Counter2, & _Direcion2, true); //Lower lip
} else {
LED_BackAndForth(LEDtoPosition(PacmanStartT), PacmanMouthOpenhalf, CRGB(255, 255, 0), &_Counter, & _Direcion, false); //Upper lip
LED_BackAndForth(LEDtoPosition(PacmanStartB), PacmanMouthOpenhalf, CRGB(255, 255, 0), &_Counter2, & _Direcion2, true); //Lower lip
}
UpdateLEDs = true;
}
} break;

default:
AnimationCounter = 0; //Stop animation
Expand Down
1 change: 1 addition & 0 deletions Arduino/Arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ void loopLEDS() {
case SINELON2: if (LastMode != Mode) StartAnimation(9, -2); break;
case SMILEY: if (LastMode != Mode) StartAnimation(10, -2); break;
case FLASH2: if (LastMode != Mode) StartAnimation(11, -2); break;
case PACMAN: if (LastMode != Mode) StartAnimation(12, -2); break;

default:
#ifdef SerialEnabled
Expand Down
4 changes: 2 additions & 2 deletions Arduino/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ struct TimeS {
unsigned long Ticks;
};
enum Modes {OFF, ON, WIFI, RESET, CLOCK,
BLINK, BPM, CONFETTI, FLASH, GLITTER, JUGGLE, MOVE, RAINBOW, SINELON, SINELON2, SMILEY, FLASH2
BLINK, BPM, CONFETTI, FLASH, GLITTER, JUGGLE, MOVE, RAINBOW, SINELON, SINELON2, SMILEY, FLASH2, PACMAN
}; //Just to make the code more clear to read, OFF=0 and ON=1 etc
String ModesString[] = {"OFF", "ON", "WIFI", "RESET", "CLOCK",
"BLINK", "BPM", "CONFETTI", "FLASH", "GLITTER", "JUGGLE", "MOVE", "RAINBOW", "SINELON", "SINELON2", "SMILEY", "FLASH2"
"BLINK", "BPM", "CONFETTI", "FLASH", "GLITTER", "JUGGLE", "MOVE", "RAINBOW", "SINELON", "SINELON2", "SMILEY", "FLASH2", "PACMAN"
}; //ALL CAPS!
const byte Modes_Amount = sizeof(ModesString) / sizeof(ModesString[0]); //Why filling this in if we can automate that? :)

Expand Down
2 changes: 1 addition & 1 deletion Arduino/handler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void handle_OnConnect() {
"let Sg=new Slider('Green');"
"let Sb=new Slider('Blue');"

"let Dm=new DropDown({name:'Mode',setParamName:'m',possibleValues:['OFF','ON','WIFI','CLOCK','BLINK','BPM','CONFETTI','FLASH','FLASH2','GLITTER','JUGGLE','MOVE','RAINBOW','SINELON','SINELON2','SMILEY'],modifySendParams:(oldParams)=>{if(Dm.value=='WIFI'){let extraData=this.getServerStateMessageData();return{...oldParams,...extraData};}},});"
"let Dm=new DropDown({name:'Mode',setParamName:'m',possibleValues:['OFF','ON','WIFI','CLOCK','BLINK','BPM','CONFETTI','FLASH','FLASH2','GLITTER','JUGGLE','MOVE','PACMAN','RAINBOW','SINELON','SINELON2','SMILEY'],modifySendParams:(oldParams)=>{if(Dm.value=='WIFI'){let extraData=this.getServerStateMessageData();return{...oldParams,...extraData};}},});"
"let Dbm=new DropDown({name:'Bootmode',setParamName:'bm',possibleValues:['OFF','ON','WIFI','CLOCK']});"
"let Ddm=new DropDown({name:'Doublepress mode',setParamName:'dm',possibleValues:['WIFI','CLOCK','BLINK','RAINBOW']});"

Expand Down

0 comments on commit 82d5a39

Please sign in to comment.