Serial 3 Channel AC 230V SSR and Dimmer
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(100);
Serial.println(" DIMMER " );
delay(500);
Serial.write('S');
delay(2000);
}
unsigned char LOAD1=0,falg=0,channel=1;//,LOAD3=0;
void loop() {
// put your main code here, to run repeatedly:
while(channel==1)
{
if(falg==0)
LOAD1=LOAD1+5;
else
LOAD1=LOAD1-5;
Serial.write('A');
CONVERT_DISPLAY(LOAD1);
delay(200);
if(LOAD1==100)
{
falg=1;
delay(2000);
}
if((LOAD1==5)&&(falg==1))
{
falg=0;
delay(2000);
channel=2;
}
}
while(channel==2)
{
if(falg==0)
LOAD1=LOAD1+5;
else
LOAD1=LOAD1-5;
Serial.write('B');
CONVERT_DISPLAY(LOAD1);
delay(200);
if(LOAD1==100)
{
falg=1;
delay(2000);
}
if((LOAD1==5)&&(falg==1))
{
falg=0;
delay(2000);
channel=3;
}
}
while(channel==3)
{
if(falg==0)
LOAD1=LOAD1+5;
else
LOAD1=LOAD1-5;
Serial.write('C');
CONVERT_DISPLAY(LOAD1);
delay(200);
if(LOAD1==100)
{
falg=1;
delay(2000);
}
if((LOAD1==5)&&(falg==1))
{
falg=0;
delay(2000);
channel=1;
}
}
}
void CONVERT_DISPLAY(unsigned int d)
{
unsigned char dig1,dig2,dig3,dig[3];
unsigned char x;
unsigned char temp;
temp=d;
temp=temp/10;
dig1=d%10;
dig2=temp%10;
dig3=temp/10;
dig[0]=dig3;
dig[1]=dig2;
dig[2]=dig1;
for(x=0;x<3;x++)
{
temp=dig[x]|0x30;
Serial.write(temp);
}
}