Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h>
- #include <Adafruit_NeoMatrix.h>
- #include <Adafruit_NeoPixel.h>
- #include <SoftwareSerial.h>
- #define PIN 6 // Define the pin connected to the LED matrix
- Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 64, PIN,
- NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
- NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
- #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
- NEO_GRB + NEO_KHZ800
- #else
- NEO_GRB + NEO_KHZ800
- #endif
- );
- SoftwareSerial serial(2, 3); // Define the software serial pins
- void setup() {
- matrix.begin();
- matrix.setTextWrap(false);
- matrix.setBrightness(50); // Set the brightness of the LED matrix
- matrix.setTextColor(matrix.Color(255, 255, 255)); // Set the text color
- serial.begin(9600); // Set the baud rate of the serial communication
- }
- void loop() {
- if (serial.available()) {
- // Read incoming data from the computer
- String data = serial.readStringUntil('\n');
- // Split the received data into individual pixel values
- String pixelValues[2048]; // Assuming maximum of 32x64=2048 pixels
- int numPixels = splitString(data, ',', pixelValues);
- if (numPixels == 2048) {
- matrix.clear();
- // Display the pixels on the LED matrix
- for (int i = 0; i < numPixels; i++) {
- int x = i % 32;
- int y = i / 32;
- // Convert the pixel value to an integer
- int pixelValue = pixelValues[i].toInt();
- // Set the color of the LED based on the pixel value
- if (pixelValue == 1) {
- matrix.drawPixel(x, y, matrix.Color(255, 255, 255));
- } else {
- matrix.drawPixel(x, y, matrix.Color(0, 0, 0));
- }
- }
- matrix.show(); // Display the updated LED matrix
- }
- }
- }
- // Function to split a string into an array based on a delimiter
- int splitString(String input, char delimiter, String output[]) {
- int counter = 0;
- String temp = "";
- for (int i = 0; i < input.length(); i++) {
- if (input.charAt(i) == delimiter) {
- output[counter] = temp;
- counter++;
- temp = "";
- } else {
- temp += input.charAt(i);
- }
- }
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement