added tap out to the display firmware, added a test firmware for sending to the display via ESP-NOW

This commit is contained in:
2025-02-23 01:57:53 +01:00
parent fe9173ca88
commit 9e708d461a
4 changed files with 134 additions and 51 deletions

View File

@@ -23,6 +23,10 @@ const int LitArray9 [] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,2
// colon // colon
const int COLONArray [] = {224,225,226,227,228,229,230,231}; const int COLONArray [] = {224,225,226,227,228,229,230,231};
// tap out
const int LitArrayTap [] = {0,1,2,3,4,5,6,7,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151};
const int LitArrayOut [] = {0,1,2,3,4,5,6,7,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159};
// set digits of the timer/clock, use: setDIGIT(<digit ID>, <Number>, <red channel intensity 0-255>, <green channel intensity 0-255>, <blue channel intensity 0-255>) // set digits of the timer/clock, use: setDIGIT(<digit ID>, <Number>, <red channel intensity 0-255>, <green channel intensity 0-255>, <blue channel intensity 0-255>)
void setDIGIT(int DIGIT_ID, int DIGIT, int RED, int GREEN, int BLUE) { void setDIGIT(int DIGIT_ID, int DIGIT, int RED, int GREEN, int BLUE) {
@@ -98,14 +102,23 @@ void setCOLON(int RED, int GREEN, int BLUE) {
} }
} }
void showTimeDisplay(int MINUTES, int SECONDS, int RED, int GREEN, int BLUE, int BRIGHTNESS) { void showTimeDisplay(int MINUTES, int SECONDS, int RED, int GREEN, int BLUE, int BRIGHTNESS) {
// set all digits // set all digits
if (MINUTES == 99) {
for (int i : LitArrayTap) {
leds_TIMER[i].setRGB(RED,GREEN,BLUE);
}
} else if (SECONDS == 99) {
for (int i : LitArrayOut) {
leds_TIMER[i].setRGB(RED,GREEN,BLUE);
}
} else {
setDIGIT(1, ((MINUTES/10)%10), RED, GREEN, BLUE); setDIGIT(1, ((MINUTES/10)%10), RED, GREEN, BLUE);
setDIGIT(2, (MINUTES%10), RED, GREEN, BLUE); setDIGIT(2, (MINUTES%10), RED, GREEN, BLUE);
setDIGIT(3, ((SECONDS/10)%10), RED, GREEN, BLUE); setDIGIT(3, ((SECONDS/10)%10), RED, GREEN, BLUE);
setDIGIT(4, (SECONDS%10), RED, GREEN, BLUE); setDIGIT(4, (SECONDS%10), RED, GREEN, BLUE);
setCOLON(RED, GREEN, BLUE); setCOLON(RED, GREEN, BLUE);
}
// actually display the digits // actually display the digits
FastLED.show(BRIGHTNESS); FastLED.show(BRIGHTNESS);
// clear the arrays // clear the arrays

View File

@@ -1,5 +1,8 @@
// ROFLS+ Arena Controller // ROFLS+ Arena Controller
// MAC address of the MCU:
// 48:27:E2:50:86:84
#include <WiFi.h> #include <WiFi.h>
#include <esp_now.h> // automatically installed for ESP32 boards, I think? #include <esp_now.h> // automatically installed for ESP32 boards, I think?
#include <Preferences.h> // automatically installed for ESP32 boards #include <Preferences.h> // automatically installed for ESP32 boards
@@ -33,6 +36,7 @@ struct_message receiveDATA;
// callback function that will be executed when data is received // callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&receiveDATA, incomingData, sizeof(receiveDATA)); memcpy(&receiveDATA, incomingData, sizeof(receiveDATA));
showTimeDisplay(receiveDATA.receiveMinutes, receiveDATA.receiveSeconds, receiveDATA.receiveREDchannel, receiveDATA.receiveGREENchannel, receiveDATA.receiveBLUEchannel, receiveDATA.receiveBrightness);
} }
void setup() { void setup() {
@@ -51,21 +55,16 @@ void setup() {
// sanity check delay - allows reprogramming if accidently blowing power w/leds // sanity check delay - allows reprogramming if accidently blowing power w/leds
delay(2000); delay(2000);
// This function sets up the leds and tells the controller about them // This function sets up the leds and tells the controller about them
FastLED.addLeds<WS2811Controller800Khz, LED_DATA_PIN_TIMER, GRB>(leds_TIMER, NUM_LEDS_TIMER); // GRB ordering is typical //FastLED.addLeds<WS2811Controller800Khz, LED_DATA_PIN_TIMER, GRB>(leds_TIMER, NUM_LEDS_TIMER); // GRB ordering is typical
FastLED.addLeds<WS2812B, LED_DATA_PIN_TIMER, GRB>(leds_TIMER, NUM_LEDS_TIMER); // GRB ordering is typical
//FastLED.setMaxRefreshRate(10, true); //FastLED.setMaxRefreshRate(10, true);
FastLED.setMaxPowerInVoltsAndMilliamps(5,2000); // Limit to 10W of output power FastLED.setMaxPowerInVoltsAndMilliamps(5,2000); // Limit to 10W of output power
// set default values // set default values
receiveDATA.receiveMinutes = 12; // default screen, just to show it's up and running but hasn't received any data, should display 00:00 in blue
receiveDATA.receiveSeconds = 34; showTimeDisplay(0, 0, 0, 0, 255, 32);
receiveDATA.receiveREDchannel = 128;
receiveDATA.receiveGREENchannel = 128;
receiveDATA.receiveBLUEchannel = 128;
receiveDATA.receiveBrightness = 16;
} }
void loop() { void loop() {
// update the LED Display // nothing to see here, everything get's handled by the callback function
showTimeDisplay(receiveDATA.receiveMinutes, receiveDATA.receiveSeconds, receiveDATA.receiveREDchannel, receiveDATA.receiveGREENchannel, receiveDATA.receiveBLUEchannel, receiveDATA.receiveBrightness);
// showTimeDisplay(12, 34, 150, 0, 150, 16);
} }

View File

@@ -0,0 +1,106 @@
// ROFLS+ Arena Controller
#include <WiFi.h>
#include <esp_now.h> // automatically installed for ESP32 boards, I think?
#include <Preferences.h> // automatically installed for ESP32 boards
#include <CountDown.h> // https://github.com/RobTillaart/CountDown
#include <StopWatch.h> // https://github.com/RobTillaart/StopWatch_RT
const int countdownTIME = 3; // countdown timer length in minutes
const int countdownToFight = 3; // countdown timer length in seconds
const int PITreleaseTime = 90; // automatic pit release time in seconds until end of countdown
bool countdownPAUSED = false;
CountDown FightCountDown[1];
// Rumble stopwatch
StopWatch rumbleTIME;
int CLOCK_LED_BRIGHTNESS = 16; // 64 is okay
// REPLACE WITH YOUR RECEIVER MAC Address
uint8_t broadcastAddress[] = {0x48, 0x27, 0xE2, 0x5D, 0xB6, 0x84};
// ESP-NOW config
// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
int sendMinutes;
int sendSeconds;
int sendREDchannel;
int sendGREENchannel;
int sendBLUEchannel;
int sendBrightness;
} struct_message;
// Create a struct_message called remoteDATA
struct_message sendDATA;
esp_now_peer_info_t peerInfo;
// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void setup() {
// Serial.begin(115200);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_register_send_cb(OnDataSent);
// Register peer
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
// set rumble stopwatch resolution to seconds
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &sendDATA, sizeof(sendDATA));
sendDATA.sendMinutes = 88;
sendDATA.sendSeconds = 88;
sendDATA.sendREDchannel = 63;
sendDATA.sendGREENchannel = 0;
sendDATA.sendBLUEchannel = 0;
sendDATA.sendBrightness = 32;
}
void loop() {
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &sendDATA, sizeof(sendDATA));
sendDATA.sendMinutes = 88;
sendDATA.sendSeconds = 88;
sendDATA.sendREDchannel = 63;
sendDATA.sendGREENchannel = 0;
sendDATA.sendBLUEchannel = 0;
sendDATA.sendBrightness = 32;
delay(2000);
// if (result == ESP_OK) {
// Serial.println("Sent with success");
// }
// else {
// Serial.println("Error sending the data");
// }
//showTimeDisplay((FightCountDown[0].remaining()/60%10), (FightCountDown[0].remaining()%60), 0, XDAS, 0);
}

View File

@@ -1,35 +0,0 @@
/// @file Blink.ino
/// @brief Blink the first LED of an LED strip
/// @example Blink.ino
#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 3
// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 3
//#define CLOCK_PIN 13
// Define the array of leds
CRGB leds[NUM_LEDS];
#define POTI_PIN 2
int POTI_VALUE = 0;
void setup() {
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
}
void loop() {
leds[0] = CRGB::Red;
leds[1] = CRGB::Blue;
leds[2] = CRGB::Green;
FastLED.setBrightness(map(analogRead(POTI_PIN), 0, 8191, 8, 255));
FastLED.show();
delay(1);
//POTI_VALUE = map(analogRead(POTI_PIN), 0, 8191, 0, 255);
}