95 lines
1.5 KiB
C++
95 lines
1.5 KiB
C++
#include <MsTimer2.h>
|
|
|
|
#define RS232_1 Serial1
|
|
|
|
int8_t task_count = 0;
|
|
bool timer1_fire = false;
|
|
|
|
#define nLED_USER 53
|
|
#define D_OUT7 30
|
|
|
|
#define digital_toggle(a) digitalWrite(a, !digitalRead(a))
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
Serial1.begin(9600);
|
|
|
|
pinMode(nLED_USER, OUTPUT);
|
|
pinMode(D_OUT7, OUTPUT);
|
|
|
|
MsTimer2::set(100, timer1);
|
|
MsTimer2::start(); // simple task switch
|
|
}
|
|
|
|
void task_io();
|
|
void task_io_1();
|
|
void task_io_2();
|
|
|
|
void (*func_task[10])() = {
|
|
0,
|
|
0,
|
|
task_io,
|
|
0,
|
|
0,
|
|
|
|
task_io_2,
|
|
0,
|
|
0,
|
|
task_io_1,
|
|
0,
|
|
};
|
|
|
|
void task_io()
|
|
{
|
|
digital_toggle(nLED_USER);
|
|
delay(1000);
|
|
digital_toggle(nLED_USER);
|
|
delay(1000);
|
|
}
|
|
|
|
void task_io_1()
|
|
{
|
|
digital_toggle(D_OUT7);
|
|
delay(1000);
|
|
digital_toggle(D_OUT7);
|
|
delay(1000);
|
|
}
|
|
|
|
void task_io_2()
|
|
{
|
|
unsigned long now = millis();
|
|
if (Serial1) {Serial1.println(now);}
|
|
}
|
|
|
|
void timer1() { timer1_fire = true; }
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
|
|
if (timer1_fire) {
|
|
timer1_fire = false;
|
|
if (func_task[task_count]) func_task[task_count]();
|
|
if (++task_count == 10) task_count = 0;
|
|
}
|
|
|
|
}
|
|
/*
|
|
digital_toggle(nLED_USER);
|
|
delay(1000);
|
|
digital_toggle(nLED_USER);
|
|
delay(1000);
|
|
digitalWrite(D_OUT7, HIGH);
|
|
delay(1000);
|
|
digitalWrite(D_OUT7, LOW);
|
|
delay(1000);
|
|
|
|
|
|
if (++task_count == 100) task_count = 0;
|
|
|
|
if (task_count == 0) {
|
|
|
|
unsigned long now = millis();
|
|
|
|
if (Serial1) {Serial1.println(now);}
|
|
}
|
|
*/ |