hw_timer_t *mt=NULL;
hw_timer_t *mt1=NULL;
int t = 0;
int s = 0;
int wait = 0;
int d=0;
void v(int x, int c,int y)
{
if (wait == 0)
{
if ((s % 2 == 0))
{
digitalWrite(25, HIGH);
}
else
{
digitalWrite(25, LOW);
}
s++;
if (s >= x*2)
{
wait = 1;
s=0;
}
}
else
{
wait++;
if (wait > y)
{
wait = 0;
if (c == 1)t = 0; else
{
t = 1;
}
if(d==0)d=1;else{d=0;
}
}
}
}
void IRAM_ATTR onTimer()
{
digitalWrite(2,!digitalRead(2));
if(d==1)
v(6, 1,4);
}
void IRAM_ATTR onTimer1()
{
if(d==0)
v(3, 0,2);
}
void setup()
{
pinMode(2, OUTPUT);
pinMode(25, OUTPUT);
mt=timerBegin(0,80,true); //TIMER 1-3 //80 คือ MHz มีสูงสุด
timerAttachInterrupt(mt,&onTimer,true);
timerAlarmWrite(mt,500000,true);
timerAlarmEnable(mt);
mt1=timerBegin(1,80,true);
timerAttachInterrupt(mt1,&onTimer1,true);
timerAlarmWrite(mt1,1000000,true);
timerAlarmEnable(mt1);
}
void loop()
{
// put your main code here, to run repeatedly:
}