// includes start
#include <Arduino.h>
#include <Microduino_Matrix.h>
#include <Microduino_Key.h>
#include <Microduino_ColorLED.h>
// includes end
// definition start
uint8_t playSound(uint8_t pin, uint8_t songNum);
void playingRest();
boolean playingStop();
void strip_transition(ColorLED &strip_led, uint8_t num, long colorbegin, long colorend, int _duration);
// definition end
#define SONG_SUM 11
uint8_t Addr64[MatrixPix_X][MatrixPix_Y] = {{64}};
Matrix display64 = Matrix(Addr64, TYPE_COLOR);
uint8_t rgbArray_64_347414241_2[8][8][3] = {{{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255}},{{0,0,0},{0,0,0},{0,0,0},{171,0,255},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{171,0,255},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255}},{{0,0,0},{0,0,0},{0,0,0},{171,0,255},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{171,0,255},{0,0,0},{171,0,255},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{171,0,255},{0,0,0},{0,0,0},{171,0,255},{0,0,0}},{{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255},{171,0,255}}};
uint8_t rgbArray_64_518066172_3[8][8][3] = {{{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132}},{{0,0,0},{0,0,0},{0,0,0},{255,0,132},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{255,0,132},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132}},{{0,0,0},{0,0,0},{0,0,0},{255,0,132},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{255,0,132},{0,0,0},{255,0,132},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{255,0,132},{0,0,0},{0,0,0},{255,0,132},{0,0,0}},{{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132},{255,0,132}}};
uint8_t rgbArray_64_384374321_4[8][8][3] = {{{0,0,0},{255,0,247},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{255,0,247},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{255,0,247},{255,0,247},{255,0,247},{255,0,247},{0,0,0},{255,0,247},{255,0,247},{255,0,247}},{{0,0,0},{255,0,247},{0,0,0},{255,0,247},{0,0,0},{255,0,247},{0,0,0},{255,0,247}},{{0,0,0},{255,0,247},{0,0,0},{255,0,247},{0,0,0},{255,0,247},{255,0,247},{255,0,247}},{{255,0,247},{0,0,0},{0,0,0},{255,0,247},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{255,0,247},{255,0,247},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{255,0,247},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}};
uint8_t rgbArray_64_2030562_5[8][8][3] = {{{0,255,222},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,255,222},{0,0,0},{0,0,0}},{{0,0,0},{0,255,222},{0,0,0},{0,0,0},{0,0,0},{0,255,222},{0,0,0},{0,0,0}},{{0,0,0},{0,0,0},{0,255,222},{0,0,0},{0,0,0},{0,255,222},{0,0,0},{0,0,0}},{{0,255,222},{0,0,0},{0,0,0},{0,255,222},{0,255,222},{0,255,222},{0,255,222},{0,255,222}},{{0,0,0},{0,255,222},{0,0,0},{0,255,222},{0,0,0},{0,255,222},{0,0,0},{0,255,222}},{{0,0,0},{0,0,0},{0,0,0},{0,255,222},{0,255,222},{0,255,222},{0,255,222},{0,255,222}},{{0,0,0},{0,255,222},{0,0,0},{0,255,222},{0,0,0},{0,255,222},{0,0,0},{0,255,222}},{{0,255,222},{0,0,0},{0,0,0},{0,255,222},{0,255,222},{0,255,222},{0,255,222},{0,255,222}}};
DigitalKey key_4(4);
uint16_t toneList[] = { 262, 294, 330, 349, 392, 440, 494, 523, 587, 659, 698, 784, 880, 988, 1046, 1175, 1318, 1397, 1568, 1760, 1967 };
uint8_t music_1[] = { 12, 10, 12, 10, 12, 10, 9, 10, 12, 12, 12, 10, 13, 12, 10, 12, 10, 9, 8, 9, 10, 12, 10, 9, 8, 9, 10, 0 };
uint8_t rhythm_1[] = { 4, 2, 4, 2, 2, 2, 2, 2, 8, 2, 4, 2, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 8 };
uint8_t music_2[] = { 8, 9, 10, 8, 8, 9, 10, 8, 10, 11, 12, 10, 11, 12, 0 };
uint8_t rhythm_2[] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8 };
uint8_t music_3[] = { 5, 8, 8, 10, 13, 10, 12, 12, 13, 12, 10, 11, 10, 9, 6, 9, 9, 11, 14, 14, 13, 12, 11, 11, 10, 6, 7, 8, 9 , 0 };
uint8_t rhythm_3[] = { 2, 1, 2, 1, 2, 1, 4, 2, 1, 2, 1, 2, 1, 4, 2, 1, 2, 1, 2, 1, 2, 1, 4, 2, 1, 2, 4, 2, 8 };
uint8_t music_4[] = { 5, 5, 6, 5, 8, 7, 5, 5, 6, 5, 9, 8, 5, 5, 12, 10, 8, 7, 6, 11, 11, 10, 8, 9, 8, 0 };
uint8_t rhythm_4[] = { 2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 8 };
uint8_t music_5[] = { 12, 13, 12, 13, 12, 13, 12, 12, 15, 14, 13, 12, 13, 12, 12, 12, 10, 10, 12, 12, 10, 9, 11, 10, 9, 8, 9, 8, 0 };
uint8_t rhythm_5[] = { 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4 };
uint8_t music_6[] = { 8, 8, 10, 8, 8, 10, 22, 13, 13, 13, 12, 13, 12, 8, 10, 22, 15, 13, 13, 12, 13, 12, 8, 9, 22, 14, 14, 12, 10, 12, 0 };
uint8_t rhythm_6[] = { 4, 4, 8, 2, 4, 4, 4, 4, 4, 2, 2, 4, 2, 4, 4, 4, 2, 2, 2, 2, 8, 2, 4, 4, 4, 4, 2, 2, 4, 16 };
uint8_t music_7[] = { 6, 8, 9, 10, 12, 10, 8, 9, 6, 22, 8, 9, 10, 12, 12, 13, 9, 10, 22, 10, 12, 13, 12, 13, 15, 14, 13, 12, 13, 10, 8, 9, 10, 12, 8, 6, 8, 9, 10, 13, 12 , 0 };
uint8_t rhythm_7[] = { 2, 2, 2, 4, 2, 2, 2, 4, 8, 2, 2, 2, 2, 4, 2, 4, 4, 8, 4, 2, 2, 8, 4, 2, 2, 1, 1, 2, 2, 4, 2, 2, 4, 2, 4, 4, 2, 2, 2, 2, 18 };
uint8_t music_8[] = { 10, 8, 9, 6, 10, 9, 8, 9, 6, 10, 8, 9, 9, 12, 10, 7, 8, 8, 7, 6, 7, 8, 9, 5, 13, 12, 10, 10, 9, 8, 9, 10, 9, 10, 9, 12, 12, 12, 12, 12, 12, 0 };
uint8_t rhythm_8[] = { 4, 4, 4, 4, 2, 2, 2, 2, 8, 4, 4, 4, 4, 2, 2, 4, 4, 2, 2, 4, 2, 2, 4, 4, 2, 2, 4, 4, 2, 4, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 4 };
uint8_t music_9[] = { 10, 12, 15, 13, 12, 10, 12, 13, 15, 12, 15, 17, 16, 15, 16, 15, 13, 15, 12 , 0 };
uint8_t rhythm_9[] = { 2, 2, 2, 2, 8, 2, 2, 2, 2, 8, 4, 2, 4, 4, 2, 2, 2, 2, 8 };
uint8_t music_10[] = { 10, 10, 10, 8, 5, 5, 22, 10, 10, 10, 8, 10, 22, 12, 12, 10, 8, 5, 5, 5, 6, 7, 8, 10, 9, 0 };
uint8_t rhythm_10[] = { 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 4 };
uint8_t music_11[] = {8, 9, 10, 8, 8, 9, 10, 8, 10, 11, 12, 10, 11, 12, 0 };
uint8_t rhythm_11[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4 };
const uint8_t * Pmusic[SONG_SUM] = { music_1, music_2, music_3, music_4, music_5, music_6, music_7, music_8, music_9, music_10, music_11 };
const uint8_t * Prhythm[SONG_SUM] = { rhythm_1, rhythm_2, rhythm_3, rhythm_4, rhythm_5, rhythm_6, rhythm_7, rhythm_8, rhythm_9, rhythm_10, rhythm_11 };
uint32_t playTimer = 0;
int8_t songNumC = -1;
uint8_t songIndex;
uint8_t playIndex = 0;
ColorLED strip_A0 = ColorLED(16, A0);
DigitalKey key_6(6);
uint16_t timer;
uint8_t playSound(uint8_t pin, uint8_t songNum) {
	songIndex = songNum;
	if (songNum > SONG_SUM - 1) {
		noTone(pin);
		return;
	}
	if (playIndex == 100 || songNumC != songNum) {
		playIndex = 0;
		songNumC = songNum;
	}
	if (millis() > playTimer && (*(Pmusic[songNum] + playIndex / 2))) {
		if (playIndex % 2 == 0) {
			if (*(Pmusic[songNum] + playIndex / 2) != 22) {
				tone(pin, toneList[*(Pmusic[songNum] + playIndex / 2) - 1]);
			} else {
				noTone(pin);
			}
			playTimer = millis() + *(Prhythm[songNum] + playIndex / 2) * 75;
		} else {
			noTone(pin);
			playTimer = millis() + 40;
		}
		playIndex++;
	}
}
void playingRest() {
	playIndex = 0;
}
boolean playingStop() {
	if (*(Pmusic[songIndex] + playIndex / 2)) {
		return false;
	} else {
		return true;
	}
}
void strip_transition(ColorLED &strip_led, uint8_t num, long colorbegin, long colorend, int _duration) {
	uint8_t ColorR[3], ColorG[3], ColorB[3];
	ColorR[0] = colorbegin >> 16;
	ColorG[0] = colorbegin >> 8 & 0xFF;
	ColorB[0] = colorbegin & 0xFF;
	ColorR[1] = colorend >> 16;
	ColorG[1] = colorend >> 8 & 0xFF;
	ColorB[1] = colorend & 0xFF;
	for (int i = 0; i < _duration; i++) {
		ColorR[2] = map(i, 0, _duration, ColorR[0], ColorR[1]);
		ColorG[2] = map(i, 0, _duration, ColorG[0], ColorG[1]);
		ColorB[2] = map(i, 0, _duration, ColorB[0], ColorB[1]);
		strip_led.setPixelColor(num, ColorR[2], ColorG[2] , ColorB[2]);
		strip_led.show();
		delay(1);
	}
	delay(15);
}
void setup() {
	// setup define start
	Wire.begin();
	key_4.begin(INPUT_PULLUP);
	strip_A0.begin();
	key_6.begin(INPUT_PULLUP);
	// setup define end
	timer = millis();
}
void loop() {
	if((((millis())-(timer)) < 1000)) {
		for (int y = 0; y < 8; y++) {
			for (int x = 0; x < 8; x++) {
				display64.setLedColor(x, y, rgbArray_64_347414241_2[y][x][0], rgbArray_64_347414241_2[y][x][1], rgbArray_64_347414241_2[y][x][2]);
			}
		}
	} else {
		if((((millis())-(timer)) < 2000)) {
			for (int y = 0; y < 8; y++) {
				for (int x = 0; x < 8; x++) {
					display64.setLedColor(x, y, rgbArray_64_518066172_3[y][x][0], rgbArray_64_518066172_3[y][x][1], rgbArray_64_518066172_3[y][x][2]);
				}
			}
		} else {
			if((((millis())-(timer)) < 3000)) {
				for (int y = 0; y < 8; y++) {
					for (int x = 0; x < 8; x++) {
						display64.setLedColor(x, y, rgbArray_64_384374321_4[y][x][0], rgbArray_64_384374321_4[y][x][1], rgbArray_64_384374321_4[y][x][2]);
					}
				}
			} else {
				if((((millis())-(timer)) < 4000)) {
					for (int y = 0; y < 8; y++) {
						for (int x = 0; x < 8; x++) {
							display64.setLedColor(x, y, rgbArray_64_2030562_5[y][x][0], rgbArray_64_2030562_5[y][x][1], rgbArray_64_2030562_5[y][x][2]);
						}
					}
				} else {
					timer = millis();
				}
			}
		}
	}
	if((key_4.readVal(KEY_PRESSED))) {
		while(!((key_4.readVal(KEY_RELEASED))));
		while (!playingStop()) {
			playSound(8, 1-1);
		}
		playingRest();
		strip_transition(strip_A0, 0, 0xf2874f, 0xbce9f4, 0.5 * 1000);
		strip_transition(strip_A0, 1, 0x31f2e5, 0x7914f4, 0.5 * 1000);
		strip_transition(strip_A0, 2, 0x082bf2, 0xf40a63, 0.5 * 1000);
		strip_transition(strip_A0, 3, 0xf20707, 0xbf00f4, 0.5 * 1000);
		strip_transition(strip_A0, 4, 0xf207d9, 0xe7f402, 0.5 * 1000);
		strip_transition(strip_A0, 5, 0xbdf214, 0x0014f4, 0.5 * 1000);
		delay(3 * 1000);
	}
	if((key_6.readVal(KEY_PRESSED))) {
		while(!((key_6.readVal(KEY_RELEASED))));
		while (!playingStop()) {
			playSound(8, 2-1);
		}
		playingRest();
		strip_transition(strip_A0, 0, 0x4fbef2, 0xf40a0a, 0.5 * 1000);
		strip_transition(strip_A0, 1, 0x95f24f, 0xf400d7, 0.5 * 1000);
		strip_transition(strip_A0, 2, 0xf2874f, 0x1119f4, 0.5 * 1000);
		strip_transition(strip_A0, 3, 0x0ffff7, 0x6d00f4, 0.5 * 1000);
		strip_transition(strip_A0, 4, 0xf21087, 0xbce9f4, 0.5 * 1000);
		strip_transition(strip_A0, 5, 0xf20000, 0xe200f4, 0.5 * 1000);
		delay(3 * 1000);
	}
}
1. 闪光加油播放器
编程语言: Scratch3
软件工具:mDesigner 3
创建时间:2019/08/26
作者: | 吴紫玉 |
立即注册