回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

通过定点亮灭实现下雨效果 简单

头像 小徐的MC 2024.02.04 159 0

screenshots-3.mp-1707023054888.png

代码
/*!
 * MindPlus
 * microbit
 *
 */
#include <Microbit_Matrix.h>
#include <Microbit_Sensors.h>
// 函数声明
void buttonABCallback();
void ScreenUpEvent();
void buttonACallback();
void buttonBCallback();
// 静态常量
const uint8_t bbcBitmap[][5] = {
	{B01010,B10101,B10001,B01010,B00100},
	{B01000,B01000,B01000,B01110,B00000},
	{B01110,B01010,B01010,B01010,B01110},
	{B01010,B01010,B01010,B01010,B00100},
	{B01110,B01000,B01110,B01000,B01110},
	{B00000,B01010,B00000,B10001,B01110},
	{B11111,B10001,B01010,B10001,B01110},
	{B11111,B10001,B01010,B10001,B11111},
	{B11111,B11111,B10001,B01010,B00000},
	{B10101,B01010,B10101,B01010,B10101},
	{B11110,B11100,B11100,B11000,B11000},
	{B00001,B00011,B00011,B00111,B01111}
};


// 主程序开始
void setup() {
	onEvent(ID_BUTTON_AB, PRESS, buttonABCallback);
	Sensors.onGesture(Sensors.ScreenUp,ScreenUpEvent);
	onEvent(ID_BUTTON_A, PRESS, buttonACallback);
	onEvent(ID_BUTTON_B, PRESS, buttonBCallback);
	MMatrix.clear();
}
void loop() {
	MMatrix.show(bbcBitmap[0]);
	delay(1000);
	MMatrix.show(bbcBitmap[1]);
	delay(1000);
	MMatrix.show(bbcBitmap[2]);
	delay(1000);
	MMatrix.show(bbcBitmap[3]);
	delay(1000);
	MMatrix.show(bbcBitmap[4]);
}


// 事件回调函数
void buttonABCallback() {
	MMatrix.clear();
	while (1) {
		MMatrix.drawPixel(2, 4, LED_ON);
		delay(1000);
		MMatrix.drawPixel(2, 4, LED_OFF);
		MMatrix.drawPixel(2, 3, LED_ON);
		delay(1000);
		MMatrix.drawPixel(2, 3, LED_OFF);
		MMatrix.drawPixel(2, 3, LED_ON);
		delay(1000);
		MMatrix.drawPixel(2, 3, LED_OFF);
		MMatrix.drawPixel(2, 2, LED_ON);
		delay(1000);
		MMatrix.drawPixel(2, 2, LED_OFF);
		MMatrix.drawPixel(2, 1, LED_ON);
		delay(1000);
		MMatrix.drawPixel(2, 1, LED_OFF);
		MMatrix.drawPixel(2, 0, LED_ON);
		delay(1000);
		MMatrix.drawPixel(2, 0, LED_OFF);
		while (1) {
			MMatrix.drawPixel(1, 4, LED_ON);
			delay(1000);
			MMatrix.drawPixel(1, 4, LED_OFF);
			MMatrix.drawPixel(1, 3, LED_ON);
			delay(1000);
			MMatrix.drawPixel(1, 3, LED_OFF);
			MMatrix.drawPixel(1, 2, LED_ON);
			delay(1000);
			MMatrix.drawPixel(1, 2, LED_OFF);
			MMatrix.drawPixel(1, 1, LED_ON);
			delay(1000);
			MMatrix.drawPixel(1, 1, LED_OFF);
			MMatrix.drawPixel(1, 0, LED_ON);
			delay(1000);
			MMatrix.drawPixel(1, 0, LED_OFF);
			yield();
		}
		yield();
	}
}
void ScreenUpEvent() {
	MMatrix.clear();
	while (1) {
		MMatrix.show(bbcBitmap[0]);
		delay(3000);
		MMatrix.show(bbcBitmap[5]);
		yield();
	}
}
void buttonACallback() {
	MMatrix.clear();
	while (1) {
		MMatrix.show(bbcBitmap[6]);
		delay(1000);
		MMatrix.show(bbcBitmap[7]);
		delay(1000);
		MMatrix.show(bbcBitmap[8]);
		delay(1000);
		MMatrix.show(bbcBitmap[9]);
		yield();
	}
}
void buttonBCallback() {
	MMatrix.clear();
	while (1) {
		if (((Sensors.acceleration(Sensors.X))<0)) {
			MMatrix.show(bbcBitmap[10]);
		}
		if ((0<(Sensors.acceleration(Sensors.X)))) {
			MMatrix.show(bbcBitmap[11]);
		}
		yield();
	}
}

评论

user-avatar