Hi,
I have a pwm signal with one positive leading and then 16 impulses:
Here you can see the size of impuls 1,3 and 4 is smaller and that is because the inputs are aktive
My goal is to have the arduino due listen on 6 input, and then sending the result to a raspberry pi.
Furthermore I need be able to output similar pwm signals to 9 outputs.
My code today is:
int inputpin0 = A0;
unsigned long duration;
int duration_channel[16];
int channel[16];
int checksum;
int checksum_old;
void setup()
{
pinMode(inputpin0, INPUT);
Serial.begin(9600);
}
void loop()
{
duration = pulseIn(inputpin0, HIGH);
if (duration > 3000)
{
for (int x = 0; x < 16; x++)
{
duration_channel[x] = pulseIn(inputpin0, HIGH);
}
for (int x = 0; x < 16; x++)
{
if (duration_channel[x] > 250)
channel[x] = 0;
else
channel[x] = 1;
}
checksum_old = checksum;
checksum = 0;
for (int x = 0; x < 16; x++)
{
checksum = checksum + channel[x];
}
if (checksum != checksum_old)
{
for (int x = 0; x < 16; x++)
{
Serial.print(inputpin0);
Serial.print("/");
Serial.print(x);
Serial.print("/");
Serial.print(channel[x]);
Serial.println();
}
}
}
}
On my pi I listen to on the serial console for my print, and handle the actions with node.js.
But my code doesn't scale very well, can anyone point me in the correct direction?