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 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 }; // intervals keep LED on.
unsigned int timedown[96]={2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2}; // intervals keep dark.
static rt_device_t Serial;
int led=0;
void swrite(void *led, void *lit){
rt_device_write(Serial,0,&led,1);
rt_device_write(Serial,0,&lit,1);
rt_device_write(Serial,0,&st,1);
}
static void led_entry(void *parameters){
led++;
while(1){
if(timeclose[led]<=0 || (timeup[led]==0 && timedown[led]==0)){
return;
}
if(timeup[led]!=0){
swrite(&led,&light[led]);
rt_thread_mdelay(timeup[led]*1000);
}
if(timedown[led]!=0){
swrite(&led,0);
rt_thread_mdelay(timedown[led]*1000);
}
timeclose[led]-=(timeup[led]+timedown[led]);
}
}
/*
static void control_entry(void *parameter){
rt_uint8_t ser[10];
rt_uint8_t led;
Serial.readBytes(ser,11);
if(ser[10]==st){
led=ser[0];
light[led]=ser[1];
timeup[led]=ser[2]*256+ser[3];
timedown[led]=ser[4]*256+ser[5];
timeclose[led]=ser[6]*256*256*256+ser[7]*256*256+ser[8]*256+ser[9];
}
*/
int main(int argc, char **argv)
{
Serial=rt_device_find("uart1");
rt_device_open(Serial , RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX );
rt_thread_t tid=RT_NULL;
char lleedd[2]={'0','0'};
for(rt_uint8_t l=0;l<96;l++){
itoa((int)l,lleedd,10);
tid=rt_thread_create(strcpy("led",lleedd),
led_entry, &l,
LED_STACK_SIZE, LED_PRIORITY, LED_TIMESLICE);
if(tid!=RT_NULL)
rt_thread_startup(tid);
}
// tid=rt_thread_create("control",
// control_entry, (void*) 1,
// LED_STACK_SIZE*96, LED_PRIORITY-1, LED_TIMESLICE);
return 0;
}
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!