Skip to content

Instantly share code, notes, and snippets.

@shikarunochi
Last active May 15, 2020 05:12
Show Gist options
  • Select an option

  • Save shikarunochi/cf34b98cbaa1b8c0ca0969ea685ca5e3 to your computer and use it in GitHub Desktop.

Select an option

Save shikarunochi/cf34b98cbaa1b8c0ca0969ea685ca5e3 to your computer and use it in GitHub Desktop.
サイコロ for M5Atom Matrix
#include "M5Atom.h"
/* this Example only for M5Atom Matrix */
const unsigned numberPixel[10][25] = {
{ 0, 1, 1, 1, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 1, 1, 0
},
{ 0, 0, 1, 0, 0,
0, 1, 1, 0, 0,
0, 0, 1, 0, 0,
0, 0, 1, 0, 0,
0, 1, 1, 1, 0
},
{ 0, 1, 1, 1, 0,
0, 0, 0, 1, 0,
0, 1, 1, 1, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0
},
{ 0, 1, 1, 1, 0,
0, 0, 0, 1, 0,
0, 1, 1, 1, 0,
0, 0, 0, 1, 0,
0, 1, 1, 1, 0
},
{ 0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 1, 1, 0,
0, 0, 0, 1, 0,
0, 0, 0, 1, 0
},
{ 0, 1, 1, 1, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0,
0, 0, 0, 1, 0,
0, 1, 1, 1, 0
},
{ 0, 1, 1, 1, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0,
0, 1, 0, 1, 0,
0, 1, 1, 1, 0
},
{ 0, 1, 1, 1, 0,
0, 1, 0, 1, 0,
0, 0, 0, 1, 0,
0, 0, 0, 1, 0,
0, 0, 0, 1, 0
},
{ 0, 1, 1, 1, 0,
0, 1, 0, 1, 0,
0, 1, 1, 1, 0,
0, 1, 0, 1, 0,
0, 1, 1, 1, 0
},
{ 0, 1, 1, 1, 0,
0, 1, 0, 1, 0,
0, 1, 1, 1, 0,
0, 0, 0, 1, 0,
0, 1, 1, 1, 0
}
};
void printNumberPixl(int number, int color){
for(int x = 0;x < 5;x++){
for(int y = 0;y < 5;y++){
if(numberPixel[number][x + y * 5]==1){
M5.dis.drawpix(x,y, color);
}else{
M5.dis.drawpix(x,y, 0x000000);
}
}
}
}
void rollDice(){
int dice = random(6);
for(int rollCount = 0;rollCount < 100;rollCount++){
dice++;
if(dice >=6){
dice = 0;
}
printNumberPixl(dice + 1, 0xf00000);
if(rollCount < 60){
delay(50);
}else if(rollCount < 80){
delay(100);
}else if(rollCount < 95){
delay(200);
}else if(rollCount < 98){
delay(500);
}else{
delay(1500);
}
}
delay(500);
printNumberPixl(dice + 1, 0x00f000);
}
void setup()
{
M5.begin(true, false, true);
delay(50);
M5.dis.clear();
randomSeed(analogRead(0));
printNumberPixl(0, 0x707070);
}
void loop()
{
if (M5.Btn.wasPressed())
{
rollDice();
}
delay(50);
M5.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment