Last active
November 23, 2021 02:40
-
-
Save ImanCol/39c53f2b27f42d8b87a7177054f7769b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#include "BluetoothSerial.h" | |
//#include "soc/soc.h" | |
//#include "soc/rtc | |
#define FASTLED_FORCE_SOFTWARE_SPI | |
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) | |
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it | |
#endif | |
//jugadores Meta | |
int meta_verde1[9] = { 469, 470, 471, 489, 490, 491, 492, 493, 494 }; | |
int meta_verde2[7] = { 495, 509, 510, 511, 512, 513, 514 }; | |
int meta_verde3[5] = { 515, 516, 517, 533, 534 }; | |
int meta_verde4[4] = { 535, 536, 537, 557 }; | |
int meta_azul1[9] = { 519, 529, 530, 531, 539, 540, 541, 542, 543 }; | |
int meta_azul2[7] = { 549, 550, 551, 552, 553, 554, 555 }; | |
int meta_azul3[5] = { 559, 560, 561, 562, 563 }; | |
int meta_azul4[4] = { 564, 565, 566, 567 }; | |
int meta_rojo1[9] = { 459, 479, 480, 481, 482, 483, 499, 500, 501 }; | |
int meta_rojo2[7] = { 502, 503, 504, 505, 506, 507, 521 }; | |
int meta_rojo3[5] = { 522, 523, 524, 525, 526 }; | |
int meta_rojo4[4] = { 527, 545, 546, 547 }; | |
int meta_amarillo1[9] = { 449, 450, 451, 452, 453, 454, 455, 456, 457 }; | |
int meta_amarillo2[7] = { 461, 462, 463, 464, 465, 466, 467 }; | |
int meta_amarillo3[5] = { 473, 474, 475, 476, 477 }; | |
int meta_amarillo4[4] = { 485, 486, 487, 497 }; | |
//Variables | |
int ficha_verde[56] = { 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55, 64, 65, 66, 67, 76, 77, 78, 79, 88, 89, 90, 91, 48, 49, 50, 51, 168, 169, 170, 171 }; | |
int exit_verde[25] = { 469, 470, 471, 489, 490, 491, 492, 493, 494, 495, 509, 510, 511, 512, 513, 514, 515, 516, 517, 533, 534, 535, 536, 537, 557 }; | |
int ficha_azul[56] = { 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 116, 117, 118, 119, 128, 129, 130, 131, 140, 141, 142, 143, 152, 153, 154, 155, 164, 165, 166, 167, 176, 177, 178, 179, 188, 189, 190, 191, 200, 201, 202, 203, 160, 161, 162, 163, 280, 281, 282, 283 }; | |
int exit_azul[25] = { 519, 529, 530, 531, 539, 540, 541, 542, 543, 549, 550, 551, 552, 553, 554, 555, 559, 560, 561, 562, 563, 564, 565, 566, 567 }; | |
int ficha_rojo[56] = { 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 228, 229, 230, 231, 240, 241, 242, 243, 252, 253, 254, 255, 264, 265, 266, 267, 276, 277, 278, 279, 288, 289, 290, 291, 300, 301, 302, 303, 312, 313, 314, 315, 272, 273, 274, 275, 372, 373, 374, 375 }; | |
int exit_rojo[25] = { 459, 479, 480, 481, 482, 483, 499, 500, 501, 502, 503, 504, 505, 506, 507, 521, 522, 523, 524, 525, 526, 527, 545, 546, 547 }; | |
int ficha_amarillo[56] = { 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 424, 425, 426, 427, 412, 413, 414, 415, 400, 401, 402, 403, 388, 389, 390, 391, 376, 377, 378, 379, 364, 365, 366, 367, 352, 353, 354, 355, 340, 341, 342, 343, 380, 381, 382, 383, 56, 57, 58, 59 }; | |
int exit_amarillo[25] = { 449, 450, 451, 452, 453, 454, 455, 456, 457, 461, 462, 463, 464, 465, 466, 467, 473, 474, 475, 476, 477, 485, 486, 487, 497 }; | |
double rgb = 0x000000; //Variable que almacena el color en hexadecimal | |
String led; //almacena el valor de KeyBT1, KeyBT2, KeyBT13 | |
String KeyBT; | |
byte s; | |
char end_char = '\n'; | |
BluetoothSerial SerialBT; | |
//Parametros de configuracion para los LEDS RGB | |
int brillo = 20; // Brillo de los LEDS , más alto mas brillo ideal 10 | |
int nleds = 569; // Numero de LEDs. Support 999 | |
int retardo = 2000; // Tiempo entre imagenes de 2 segundos | |
Adafruit_NeoPixel tira = Adafruit_NeoPixel(nleds, 2, NEO_GRB + NEO_KHZ800); // Pin 2 de Arduino salida de datos | |
//Configuraciones | |
TaskHandle_t Task1; | |
TaskHandle_t Task2; | |
void setup() { | |
//WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); | |
Serial.begin(115200); | |
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0 | |
//xTaskCreatePinnedToCore( | |
// Hikari, /* Task function. */ | |
// "Task1", /* name of task. */ | |
// 10000, /* Stack size of task */ | |
// NULL, /* parameter of the task */ | |
// 1, /* priority of the task */ | |
// &Task1, /* Task handle to keep track of created task */ | |
// 0); /* pin task to core 0 */ | |
// delay(500); | |
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1 | |
// xTaskCreatePinnedToCore( | |
// Blue, /* Task function. */ | |
// "Task2", /* name of task. */ | |
// 10000, /* Stack size of task */ | |
// NULL, /* parameter of the task */ | |
// 1, /* priority of the task */ | |
// &Task2, /* Task handle to keep track of created task */ | |
// 1); /* pin task to core 1 */ | |
// delay(500); | |
SerialBT.begin("Hikari"); //Bluetooth device name | |
SerialBT.setTimeout(100); //1.2 Resuelve el problema de comunicacion retardada con AI2 | |
Serial.println("The device started, now you can pair it with bluetooth!"); | |
tira.begin(); // inicializacion de la tira | |
tira.show(); // muestra datos en pixel | |
tira.setBrightness(brillo); // Brillo de los LEDS , más alto mas brillo ideal 15 | |
} | |
//Ciclo de programas y logica | |
//Hikari: Logica del juego | |
/* | |
void Hikari(void* pvParameters) { | |
Serial.println(xPortGetCoreID()); | |
for (;;) { | |
if (Serial.available()) {} | |
} | |
} | |
*/ | |
//Blue: Transmision Bluetooth con el Telefono al tablero | |
/* | |
void Blue(void* pvParameters) { | |
for (;;) { | |
} | |
*/ | |
//contenedor show | |
void show() { | |
tira.setPixelColor(String(led).toInt(), rgb); //asigna el led y el color | |
led = 600; //reinicia el valor led (impide que se coloque el color en el led 0) | |
tira.show(); //envia el valor a la tiras Leds | |
delay(20); //espera 20 milisegundos | |
return; //regresa a loop | |
} | |
void loop() { | |
/* | |
if (Serial.available()) { | |
SerialBT.write(Serial.read()); | |
} | |
if (SerialBT.available()) { | |
Serial.println(SerialBT.read()); | |
} | |
delay(20); | |
*/ | |
if (SerialBT.available()) //Si hay datos disponibles por Bluetooth | |
{ | |
//Guarda los valores recibidos (3 caracteres) | |
KeyBT = SerialBT.readStringUntil(end_char); //Almacena los datos recibidos en una variable como String - 1.1 Resuelve el problema de envio de datos completos | |
//KeyBT.remove(KeyBT.length() - 1, 1); //Elimina caracteres extras que se envian por SerialBT (No sucede con Serial) Elminado en 1.2 debido ah que solo funciona con la app Serial Bluetooth Terminal y no con App Inventor | |
//Colores | |
if (KeyBT == "R") { | |
rgb = 0xff0000; | |
} else if (KeyBT == "G") { | |
rgb = 0x00ff00; | |
} else if (KeyBT == "B") { | |
rgb = 0x0000ff; | |
} else if (KeyBT == "Y") { | |
rgb = 0xffff00; | |
} | |
//muestra imagen estatica del Hikari | |
else if (KeyBT == "H") { | |
led = 600; | |
for (s = 0; s < 56; s++) | |
tira.setPixelColor((int)(ficha_verde[(int)(s)]), 000, 255, 000); | |
for (s = 0; s < 25; s++) | |
tira.setPixelColor((int)(exit_verde[(int)(s)]), 000, 255, 000); | |
for (s = 0; s < 56; s++) | |
tira.setPixelColor((int)(ficha_azul[(int)(s)]), 000, 000, 255); | |
for (s = 0; s < 25; s++) | |
tira.setPixelColor((int)(exit_azul[(int)(s)]), 000, 000, 255); | |
for (s = 0; s < 56; s++) | |
tira.setPixelColor((int)(ficha_rojo[(int)(s)]), 255, 000, 000); | |
for (s = 0; s < 25; s++) | |
tira.setPixelColor((int)(exit_rojo[(int)(s)]), 255, 000, 000); | |
for (s = 0; s < 56; s++) | |
tira.setPixelColor((int)(ficha_amarillo[(int)(s)]), 255, 255, 0); | |
for (s = 0; s < 25; s++) | |
tira.setPixelColor((int)(exit_amarillo[(int)(s)]), 255, 255, 0); | |
led = 30; | |
SerialBT.println("Hikari"); | |
Serial.println(xPortGetCoreID()); | |
tira.show(); | |
} | |
//Numero de jugadores | |
else if (KeyBT == "P2") { | |
} else if (KeyBT == "P3") { | |
} else if (KeyBT == "P4") { | |
} | |
//Ficha seleccionada | |
else if (KeyBT == "F1") { | |
} else if (KeyBT == "F2") { | |
} else if (KeyBT == "F3") { | |
} else if (KeyBT == "F4") { | |
} | |
//Fichas en Meta | |
else if (KeyBT == "GM1") { | |
led = 600; | |
for (s = 0; s < 9; s++) | |
tira.setPixelColor((int)(meta_verde1[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "GM2") { | |
led = 600; | |
for (s = 0; s < 7; s++) | |
tira.setPixelColor((int)(meta_verde2[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "GM3") { | |
led = 600; | |
for (s = 0; s < 5; s++) | |
tira.setPixelColor((int)(meta_verde3[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "GM4") { | |
led = 600; | |
for (s = 0; s < 4; s++) | |
tira.setPixelColor((int)(meta_verde4[(int)(s)]), rgb); | |
tira.show(); | |
} | |
else if (KeyBT == "BM1") { | |
led = 600; | |
for (s = 0; s < 9; s++) | |
tira.setPixelColor((int)(meta_azul1[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "BM2") { | |
led = 600; | |
for (s = 0; s < 7; s++) | |
tira.setPixelColor((int)(meta_azul2[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "BM3") { | |
led = 600; | |
for (s = 0; s < 5; s++) | |
tira.setPixelColor((int)(meta_azul3[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "BM4") { | |
led = 600; | |
for (s = 0; s < 4; s++) | |
tira.setPixelColor((int)(meta_azul4[(int)(s)]), rgb); | |
tira.show(); | |
} | |
else if (KeyBT == "RM1") { | |
led = 600; | |
for (s = 0; s < 9; s++) | |
tira.setPixelColor((int)(meta_rojo1[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "RM2") { | |
led = 600; | |
for (s = 0; s < 7; s++) | |
tira.setPixelColor((int)(meta_rojo2[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "RM3") { | |
led = 600; | |
for (s = 0; s < 5; s++) | |
tira.setPixelColor((int)(meta_rojo3[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "RM4") { | |
led = 600; | |
for (s = 0; s < 4; s++) | |
tira.setPixelColor((int)(meta_rojo4[(int)(s)]), rgb); | |
tira.show(); | |
} | |
else if (KeyBT == "YM1") { | |
led = 600; | |
for (s = 0; s < 9; s++) | |
tira.setPixelColor((int)(meta_amarillo1[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "YM2") { | |
led = 600; | |
for (s = 0; s < 7; s++) | |
tira.setPixelColor((int)(meta_amarillo2[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "YM3") { | |
led = 600; | |
for (s = 0; s < 5; s++) | |
tira.setPixelColor((int)(meta_amarillo3[(int)(s)]), rgb); | |
tira.show(); | |
} else if (KeyBT == "YM4") { | |
led = 600; | |
for (s = 0; s < 4; s++) | |
tira.setPixelColor((int)(meta_amarillo4[(int)(s)]), rgb); | |
tira.show(); | |
} | |
//Serial.println("Es el color " + KeyBT); //imprime el color en el monitor Serial | |
//Comprueba si es un led | |
else { | |
Serial.println("El Led es el numero " + KeyBT); //imprime el led en el monitor Serial | |
led = (KeyBT); //almacena el valor del led | |
show(); //se dirije al contenedor show | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment