I've been trying to fix this for hours now and I'm really at a loss.
My project is to use C# and send data over serial to arduino, which will end up being a pattern in an led matrix using the FastLED library.
Not only is the data painfully slow to send (each bit taking 1 second ~3 mins in total), but it doesn't even work.
I get to the last bit and then...nothing. It just sits there.
Any help would be appreciated. (I'm aware the code is probably quite dodgy)
Also, the code in c# takes a png from my desktop and turns it into an array.
C# Code:
using System;
using System.Drawing;
using System.IO.Ports;
using System.Threading;
using System.Threading.Tasks;
namespace Net_Framework_C_Sharp
{
class Program
{
static SerialPort _serialPort;
static void send(string bit)
{
_serialPort.Write(bit);
Console.WriteLine($"Sent: {bit}\nWaiting..");
while (_serialPort.BytesToRead < 0)
{
Console.Write('.');
}
Console.WriteLine($"\nRecieved: {_serialPort.ReadLine()}\n");
}
static void Main(string[] args)
{
int x, y;
Bitmap image1;
string[,] colours = new string[64, 3];
_serialPort = new SerialPort();
_serialPort.PortName = "COM4";
_serialPort.BaudRate = 115200;
_serialPort.WriteTimeout = 500;
image1 = new Bitmap(@"[PATH TO FILE]", true);
for (x = 0; x < image1.Width; x++)
{
for (y = 0; y < image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
colours[(x * 8) + y, 0] = pixelColor.R.ToString();
colours[(x * 8) + y, 1] = pixelColor.G.ToString();
colours[(x * 8) + y, 2] = pixelColor.B.ToString();
}
}
_serialPort.Open();
for (int z = 0; z < 64; z++)
{
for (int a = 0; a < 3; a++)
{
send(colours[z, a]);
Console.WriteLine(z);
}
}
}
}
}
Arduino Code:
#include "FastLED.h"
const int data = 6, numLED = 64;
int ledPattern[63][2];
void setup() {
Serial.begin(115200);
pinMode(data, OUTPUT);
}
void printLED() {
CRGB leds[numLED];
FastLED.addLeds<NEOPIXEL, data>(leds, numLED);
for(int x = 0; x < 64; x++){
leds[x] = CRGB(ledPattern[x][0], ledPattern[x][1], ledPattern[x][2]);
Serial.println("assigned " + (String)x);
}
FastLED.show();
}
void loop() {
if (Serial.available() > 0) {
for(int a = 0; a < 64; a++){
for(int b = 0; b < 3; b++){
while (Serial.available() < 1) {
delay(100);
}
ledPattern[a][b] = Serial.parseInt();
Serial.println("ack");
}
}
printLED();
}
}