#define MAX_CHANNELS 44
int ch;
int state;
int chVal[MAX_CHANNELS] = {0};
int pins[] = {2, 3, 4, 5, 6, 7,8,9,10,11,12,13,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53};
enum states
{
IDLE,
DELIM,
READ,
DISP
};
void setup()
{
for (ch=0; ch<MAX_CHANNELS; ch++)
{
pinMode(pins[ch], OUTPUT);
// digitalWrite(pins[ch], LOW);
}
state = IDLE;
ch = 0;
// analogWrite(53,255);
Serial.begin(57600);
}
void loop()
{
while(1)
{
for (ch=0; ch<MAX_CHANNELS; ch++)
{
//if (chVal[ch] > 0)
// {
digitalWrite(pins[ch], LOW);
delay(3000);
digitalWrite(pins[ch], HIGH);
// }
// else
// {
// digitalWrite(pins[ch], HIGH);
// }
}
}
if (Serial.available())
{
switch (state)
{
case IDLE:
ch = 0;
if (Serial.read() == '+')
{
state = DELIM;
}
else
{
state = IDLE;
}
break;
case DELIM:
ch = 0;
if (Serial.read() == '>')
{
state = READ;
}
else
{
state = IDLE;
}
break;
case READ:
chVal[ch++] = Serial.read();
if (ch >= MAX_CHANNELS)
{
ch = 0;
state = DISP;
}
break;
case DISP:
state = IDLE;
for (ch=0; ch<MAX_CHANNELS; ch++)
{
if (chVal[ch] > 0)
{
digitalWrite(pins[ch], LOW);
}
else
{
digitalWrite(pins[ch], HIGH);
}
}
break;
}
}
}
Comments
Please log in or sign up to comment.