m5stack / M5StickC

M5StickC Arduino Library
MIT License
477 stars 222 forks source link

Dices problem #47

Closed MajorSnags closed 5 years ago

MajorSnags commented 5 years ago

Dices wouldn't work beyond the Shake Me message so I changed the IMU to MPU6886 and 1 was showing two spots so I adjusted the condition in the for loop in draw_dice() to d < 6. The code now works on my M5StickC and is as follows:

`/*

A couple of dices on a tiny 80x160px TFT display

Author: Alfonso de Cala alfonso@el-magnifico.org

*/

include

define DOT_SIZE 6

int dot[6][6][2] { {{35,35}}, {{15,15},{55,55}}, {{15,15},{35,35},{55,55}}, {{15,15},{15,55},{55,15},{55,55}}, {{15,15},{15,55},{35,35},{55,15},{55,55}}, {{15,15},{15,35},{15,55},{55,15},{55,35},{55,55}}, };

int16_t accX = 0; int16_t accY = 0; int16_t accZ = 0;

void setup(void) { M5.begin(); M5.MPU6886.Init();

M5.Lcd.setRotation(1);

M5.Lcd.fillScreen(TFT_GREEN);

M5.Lcd.setTextColor(TFT_BLACK); // Adding a background colour erases previous text automatically

M5.Lcd.setCursor(10, 30);
M5.Lcd.setTextSize(3); M5.Lcd.print("SHAKE ME");
delay(1000); }

void loop() {

while(1) { M5.MPU6886.getAccelAdc(&accX,&accY,&accZ); if (((float) accX) M5.MPU6886.aRes > 1 || ((float) accY) M5.MPU6886.aRes > 1 ) { break; } }

M5.Lcd.fillScreen(TFT_GREEN);

// Draw first dice delay(1000); // A little delay to increase suspense :-D int number = random(0, 6); draw_dice(5,5,number);

// Draw second dice delay(1000); number = random(0, 6); draw_dice(85,5,number);

}

void draw_dice(int16_t x, int16_t y, int n) {

M5.Lcd.fillRect(x, y, 70, 70, WHITE);

for(int d = 0; d < 6; d++) { if (dot[n][d][0] > 0) { M5.Lcd.fillCircle(x+dot[n][d][0], y+dot[n][d][1], DOT_SIZE, TFT_BLACK); } }

}`

EeeeBin commented 5 years ago

thanks :) Now fixed in https://github.com/m5stack/M5StickC/commit/2eb4e48d11805afee475874bc315e4b7eefe4691