Assemble for safety
When our athlete is out and training, he might become distracted by all the new and super fancy metrics he can track. Therefore we have implemented a safety device.
It is a warning light that can be duct taped to the athlete and will warn others about his presense.
Because we are geeks, we did write it in assembler, a language I swore to never touch again seven years ago. Thanks ARIoT.....
#define LEDPORT PORTB // Arduino pin 13 is bit 5 of port B
#define LEDPORT_DIR DDRB
#define LEDBIT 5
void setup() {
asm volatile (" sbi %[portdir], %[lbit] \n" // Set bit direction
"3: " // main loop label
" sbi %[port], %[lbit] \n" // Turn on.
/*
* About the delay loop:
* The inner loop (dec, brne) is 3 cycles.
* For one second, we want 16million cycles, or 16000000/(3*256*256) loops.
* This is "about" 81.
*/
" clr r16 \n"
" clr r17 \n"
" ldi r18, 81 \n" // 100 * 256
"1:" // 1st delay loop label
" dec r16 \n"
" brne 1b \n"
" dec r17 \n"
" brne 1b \n"
" dec r18 \n"
" brne 1b \n"
" cbi %[port], %[lbit] \n" // Turn off.
" clr r16 \n"
" clr r17 \n"
" ldi r18, 81 \n"
"2:" // 2nd delay loop label
" dec r16 \n"
" brne 2b \n"
" dec r17 \n"
" brne 2b \n"
" dec r18 \n"
" brne 2b \n"
" rjmp 3b \n"
:
: [portdir] "I" (_SFR_IO_ADDR(LEDPORT_DIR)),
[port] "I" (_SFR_IO_ADDR(LEDPORT)),
[lbit] "I" (LEDBIT)
);
}
void loop() {
}