I want a lighting fixture with ID information for my research.
Inside the WS2812's 16 by 16 light board, first it lights up all the time, then embeds an ID that is invisible to the human eye.
My idea is to make this ID number flicker at a frequency above 50hz while the display dips in half. So it can be recognized by the camera.
But now the problem, I can not be invisible. Here is my code. Ask Friends for advice or give me ready-made code.
#include <Adafruit_GFX.h> // Import the core graphics library for drawing and text handling
#include <Adafruit_NeoMatrix.h> // Import the NeoMatrix library for controlling the LED matrix
#include <Adafruit_NeoPixel.h> // Import the NeoPixel library, which NeoMatrix depends on
#include <TimerOne.h> // Import the TimerOne library for setting timer interrupts
#define PIN 5 // Define the data pin connected to the LED matrix
// Initialize the NeoMatrix object, set matrix size to 16x16, configure layout and color format
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t FULL_WHITE = matrix.Color(255, 255, 255); // Define full white color
const uint16_t DIM_WHITE = matrix.Color(170, 170, 170); // Define dim white color for displaying numbers
const int BRIGHTNESS = 5; // Set matrix brightness
volatile bool showNumber = false; // Flag to control number display
volatile unsigned long lastShowTime = 0; // Record the last time the number was displayed
const unsigned long SHOW_INTERVAL = 1000; // Set display interval to 1 ms
void setup() {
matrix.begin(); // Initialize the LED matrix
matrix.setBrightness(BRIGHTNESS); // Apply brightness setting
matrix.setTextWrap(false); // Disable automatic text wrapping
// Set up Timer1 interrupt to trigger every 11 microseconds
Timer1.initialize(999); // Initialize Timer1 with an interval of 999 microseconds
Timer1.attachInterrupt(timerCallback); // Bind the timer interrupt callback function
}
void loop() {
while(1) {
if (showNumber) {
displayNumber1(); // Display the number "1"
delayMicroseconds(1); // Display the number for 1 microsecond
showNumber = false; // Reset the display flag
matrix.fillScreen(FULL_WHITE); // Clear the number and show full white
matrix.show(); // Update the display
}
}
}
void timerCallback() {
unsigned long currentTime = micros(); // Get the current time in microseconds
if (currentTime - lastShowTime >= SHOW_INTERVAL) { // Check if the display interval has been reached
showNumber = true; // Set the flag to display the number
lastShowTime = currentTime; // Update the last display time
}
}
void displayNumber1() {
matrix.fillScreen(FULL_WHITE); // First set the background to full white
matrix.setTextColor(DIM_WHITE); // Set the text color to dim white
matrix.setTextSize(2); // Set the text size to 2
matrix.setCursor(4, 0); // Set the cursor position for text display
matrix.print("1"); // Display the number "1"
matrix.show(); // Refresh the display
}
thanks for you .
yes,it takes about 7.68ms to refresh a complete matrix of 256 leds.
And,theoretical maximum refresh rate: about 1000/7.68≈130hz
The refresh rate is enough for the invisible .
call it 8 ms. Would seem to indicate you could actually refresh at > 120 Hz, with a well - designed code.
To convince yourself that this is so, simply write a loop() that changes the colour of one pixel, then calls the update mechanism. When you've figured out what the real update rate is, then figure out what's wrong with your code. Hints:
you don't need an interrupt process
you don't need a timer
you don't need most of what you've written
whenever you find yourself using any form of a delay(), you're off the best path.
explore the functionalities and limitations of that library. Write test code to see how long each of the functions you're calling actually takes, on whatever Arduino you're running this on.
As for
Do you honestly expect you would see something displayed for 1 microsecond?
I tried 4 lamp beads and found that they were achievable.
So now the problem is 256 beads of data transmission data too much, resulting in low refresh rate.[quote="zyh_learning, post:1, topic:1317075, full:true"]
I want a lighting fixture with ID information for my research.
Inside the WS2812's 16 by 16 light board, first it lights up all the time, then embeds an ID that is invisible to the human eye.
My idea is to make this ID number flicker at a frequency above 50hz while the display dips in half. So it can be recognized by the camera.
But now the problem, I can not be invisible. Here is my code. Ask Friends for advice or give me ready-made code.
#include <Adafruit_GFX.h> // Import the core graphics library for drawing and text handling
#include <Adafruit_NeoMatrix.h> // Import the NeoMatrix library for controlling the LED matrix
#include <Adafruit_NeoPixel.h> // Import the NeoPixel library, which NeoMatrix depends on
#include <TimerOne.h> // Import the TimerOne library for setting timer interrupts
#define PIN 5 // Define the data pin connected to the LED matrix
// Initialize the NeoMatrix object, set matrix size to 16x16, configure layout and color format
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t FULL_WHITE = matrix.Color(255, 255, 255); // Define full white color
const uint16_t DIM_WHITE = matrix.Color(170, 170, 170); // Define dim white color for displaying numbers
const int BRIGHTNESS = 5; // Set matrix brightness
volatile bool showNumber = false; // Flag to control number display
volatile unsigned long lastShowTime = 0; // Record the last time the number was displayed
const unsigned long SHOW_INTERVAL = 1000; // Set display interval to 1 ms
void setup() {
matrix.begin(); // Initialize the LED matrix
matrix.setBrightness(BRIGHTNESS); // Apply brightness setting
matrix.setTextWrap(false); // Disable automatic text wrapping
// Set up Timer1 interrupt to trigger every 11 microseconds
Timer1.initialize(999); // Initialize Timer1 with an interval of 999 microseconds
Timer1.attachInterrupt(timerCallback); // Bind the timer interrupt callback function
}
void loop() {
while(1) {
if (showNumber) {
displayNumber1(); // Display the number "1"
delayMicroseconds(1); // Display the number for 1 microsecond
showNumber = false; // Reset the display flag
matrix.fillScreen(FULL_WHITE); // Clear the number and show full white
matrix.show(); // Update the display
}
}
}
void timerCallback() {
unsigned long currentTime = micros(); // Get the current time in microseconds
if (currentTime - lastShowTime >= SHOW_INTERVAL) { // Check if the display interval has been reached
showNumber = true; // Set the flag to display the number
lastShowTime = currentTime; // Update the last display time
}
}
void displayNumber1() {
matrix.fillScreen(FULL_WHITE); // First set the background to full white
matrix.setTextColor(DIM_WHITE); // Set the text color to dim white
matrix.setTextSize(2); // Set the text size to 2
matrix.setCursor(4, 0); // Set the cursor position for text display
matrix.print("1"); // Display the number "1"
matrix.show(); // Refresh the display
}
when I only use a led,I set the flicker frequency, 10hz to 200hz of the increase in function, from flicker visible to normal light, the human eye can not be observed.
Which Arduino?
I forget which pixel library it is, but there is a library that would write to more than one pin at the same time, allowing simultaneous update of, IIRC, up to 8 strings. Maybe, you could drive your16x16 as 8x32 that way.