// Example of minimal scheduler
// Pin 13 has an LED connected on most Arduino boards
// give it a name:
#define LED INTERNAL 13 // Port B bit 7
#define LED EXTERNAL 10 // Port B bit 4
#define LEDPORT PORTB
#define LEDDDR DDRB
#define L_I_BIT 1<<5
#define L_E_BIT 1<<2
//#define LOOP BIT 12 // we'll use this later but not now
// the setup routine runs once when you press reset:
void setup() {
// initialize the LED pins as an output.
LEDDDR |= ( L_I_BIT | L_E_BIT );
// pinMode (LED_ INTERNAL, OUTPUT) ;
// pinMode(LED EXTERNAL, OUTPUT) ;
// pinMode(LOOP BIT, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
static int tmp = 0;
taskA(); //assume taskA and taskB take 0 time
taskB();
delay(1); // sync
}
// Flash the on-board LED 10 times per second
void taskA(){
static int time;
time++;
if (time == 500) {
// digitalWrite/lFnTNTERNAI
LEDPORT |= L_I_BIT; // set LED output bit
}
if (time == 1000) {
// digitalWrite (LED INTERNAL, LOW);
LEDPORT &= ~L_I_BIT; // clear the bit
time = 0;
}
return;
}
// Flash the OFF-board LED 1 times per second
void taskB() {
static int time;
time++;
if (time == 200) {// because we are counting loops we can use
// digitalWrite(LED EXTERNAL, HIGH) ;
LEDPORT |= L_E_BIT;
}
if (time == 400) {
// digitalwrite(LED EXTERNAL, LOW) ;
LEDPORT &= ~L_E_BIT;
time = 0;
}
return;
}