-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrc_pwm2spi.ino
664 lines (546 loc) · 19.2 KB
/
rc_pwm2spi.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
// RC Receiver PWM to SPI slave
// ============================
// by Calvin Hass
// http://www.impulseadventure.com/elec/
//
// This code implements a simple SPI slave receiver interface
// combined with multi-channel pulse-width modulation (PWM)
// measurement. Each channel's pulse width is measured in
// microseconds and returned in a channelized register interface.
// This code can be useful for using a remote-control transmitter
// to control an Arduino / ATtiny microcontroller.
//
// - A watchdog timeout is used to detect the loss of the transmitter.
//
// - Optimized IO commands are used in the ISRs to keep the
// critical sections as fast as possible.
//
// - This example demonstrates 6 channel monitoring, but this can
// be increased/decreased if needed.
//
// Includes for ISR and IO operations
#include <avr/interrupt.h>
#include <avr/io.h>
// -----------------------
// General configuration
// -----------------------
// - Define number of channels to support.
// This is used when creating the array of SPI registers
#define NUM_CHAN 6
// - Enable periodic LED flashing of status
// 1 flash = No transmitter detected
// 3 flashes = Transmitter detected
// - Also emits 4 flashes at startup to indicate program running
// - Comment out the following line to disable
#define LED_FLASH
// TIMER INTERVALS:
// - PULSE_TIMEOUT defines the maximum delay between PWM
// pulses on a channel before it is assumed to be inactive.
// This is used for the watchdog timeout. Generally, RC
// receivers should deliver pulses approximately every
// 20ms, but one should provide ample margin in case a
// pulse gets missed.
#define PULSE_TIMEOUT 250
// - STATUS_TIMEOUT defines the delay between flashes of
// the LED for indicating status.
#define STATUS_TIMEOUT 3000
// -----------------------------------------------------------------------
// MICROCONTROLLER-SPECIFIC CONFIGURATION:
// PIN DEFINITIONS
// The pin definitions and mapping to port & pin change interrupts
// are very specific to the microcontroller model in use. The following
// values were tested to work with an ATtiny167 (Digispark Pro).
// Modifications can be done to make this work for other Arduino / AVR
// microcontrollers (such as ATmega328).
// - Pin definitions for LED & SPI
#define PIN_LED 1
#define PIN_MOSI 10 // MOSI / PA4
#define PIN_MISO 8 // MISO / PA2
#define PIN_SCK 11 // SCK / PA5
#define PIN_SS 12 // SSb / PA6 / PCINT6 (ISR PCINT0)
// - Define RC receiver pin connections to ATtiny
#define PORT_A_SS PORTA6 // PA6 / PCINT6 (ISR PCINT0)
#define PORT_A_CH5 PORTA7 // PA7 / PCINT7 (ISR PCINT0)
#define PORT_A_CH6 PORTA3 // PA3 / PCINT3 (ISR PCINT0)
#define PORT_B_CH1 PORTB0 // PB0 / PCINT8 (ISR PCINT1)
#define PORT_B_CH2 PORTB2 // PB2 / PCINT10 (ISR PCINT1)
#define PORT_B_CH3 PORTB6 // PB6 / PCINT14 (ISR PCINT1)
#define PORT_B_CH4 PORTB3 // PB3 / PCINT11 (ISR PCINT1)
// Define mapping between physical pins and the pin change interrupts
// - Pin Change interrupts in ISR PCINT0_vect / PCMSK0
#define PCINT_0_CH5 PCINT7 //PCMSK0
#define PCINT_0_CH6 PCINT3 //PCMSK0
#define PCINT_0_SS PCINT6 //PCMSK0
// - Pin Change interrupts in ISR PCINT1_vect / PCMSK1
#define PCINT_1_CH1 PCINT8 //PCMSK1
#define PCINT_1_CH2 PCINT10 //PCMSK1
#define PCINT_1_CH3 PCINT14 //PCMSK1
#define PCINT_1_CH4 PCINT11 //PCMSK1
// Define data direction register for PIN_MISO
#define DDR_MISO_PORT DDRA
#define DDR_MISO_FIELD DDA2
// -----------------------------------------------------------------------
// General channel indices
// - These are used primarily for register lookup,
// pulse counters and defining which channels are
// included in the watchdog timeout monitoring.
#define IND_CH1 0
#define IND_CH2 1
#define IND_CH3 2
#define IND_CH4 3
#define IND_CH5 4
#define IND_CH6 5
// Pulse values
// - Default pulse width used before we receive any
// from the receiver. Default is mid-point of RC
// PWM range (ie. 1500us)
#define PWM_MID 1500
// -----------------------------------------------------------------------
// GENERAL PROGRAM VARIABLES
// Pulse measurement
volatile uint16_t m_anPulseUs[NUM_CHAN]; // Pulse width measured (latest)
volatile uint8_t m_nPulsesNew = 0x00;
volatile uint8_t m_nPulsesTimeout = 0x00;
// Global status
uint8_t m_bTransmitterFail = 0;
volatile uint8_t m_bSpiXferOvf = 0;
// Pin change events
volatile uint16_t m_nPinRiseTimeUs[NUM_CHAN]; // Rising edge tstamp (from ISR)
uint16_t m_nPinKickTimeMs[NUM_CHAN]; // Last watchdog kick (from main loop)
volatile uint8_t m_nPinALast = 0x00; // Last PINA state (from ISR)
volatile uint8_t m_nPinBLast = 0x00; // Last PINB state (from ISR)
// SPI slave
volatile boolean m_bSlaveSelected = false;
volatile uint16_t m_nXferCycle = 0;
// Latched command type and reg address from COMMAND cycle
volatile uint8_t m_nRegAddr = 0;
volatile uint8_t m_bRegRWb = 0;
// Register interface
#define REGS_PER_CHAN 2
#define REG_PART_H 0
#define REG_PART_L 1
#define REG_STATUS 0
#define REG_RSVD1 1
#define REG_FIXED1 2
#define REG_FIXED2 3
#define REGBASE_CHAN 4
#define REG_MAX REGBASE_CHAN + (NUM_CHAN*REGS_PER_CHAN)
// Declare the primary register array
volatile uint8_t m_anRegArray[REG_MAX];
// -----------------------------------------------------------------------
// START OF PROGRAM CODE
// -----------------------------------------------------------------------
// Configure the interfaces, the interrupts and assign
// the default register values
void setup() {
// Initialize register array
for (int nRegInd=0;nRegInd<REG_MAX;nRegInd++) {
m_anRegArray[nRegInd] = 0x00;
}
// Special overrides
m_anRegArray[REG_FIXED1] = 0x12;
m_anRegArray[REG_FIXED2] = 0x34;
// Reset the pulse width time on all channels
// and the last watchdog kick timestamp
for (int nChan=0;nChan<NUM_CHAN;nChan++) {
// Reset pulse value
m_anPulseUs[nChan] = PWM_MID;
// Reset pulse timestamps
m_nPinRiseTimeUs[nChan] = 0;
m_nPinKickTimeMs[nChan] = 0;
}
// Default to timeout state on all channels
m_nPulsesNew = 0x00;
m_nPulsesTimeout = 0xFF;
// -------------------------
// Setup IOs
setupConfig();
// Indicate that bootloader is complete and we
// are ready to accept SPI transactions
#ifdef LED_FLASH
doBlinkFlash(4);
#endif
// Enable interrupts
sei();
}
// Initialize the IO interfaces
// - SPI interface
// - Pin change interrupts for pulse monitoring
void setupConfig() {
// Define pins for SPI
// - Start with the slave unselected
pinMode(PIN_MISO, INPUT);
pinMode(PIN_MOSI, INPUT);
pinMode(PIN_SCK, INPUT);
pinMode(PIN_SS, INPUT);
#ifdef LED_FLASH
// Initialize the LED
pinMode(PIN_LED,OUTPUT);
digitalWrite(PIN_LED,LOW);
#endif
// Reset pin change states
for (int nNumChan=0;nNumChan<NUM_CHAN;nNumChan++) {
m_nPinRiseTimeUs[nNumChan] = 0;
}
// Enable SPI and the SPI Transaction Complete ISR
SPCR |= (1 << SPE) | (1 << SPIE);
// ATtiny167:
// - Configure the pins that will trigger Pin Change event interrupts
PCMSK0 |= (1 << PCINT_0_CH5) | (1 << PCINT_0_CH6) | (1 << PCINT_0_SS);
PCMSK1 |= (1 << PCINT_1_CH1) | (1 << PCINT_1_CH2) | (1 << PCINT_1_CH3) | (1 << PCINT_1_CH4);
// - Enable the Pin Change interrupts
PCICR |= (1<<PCIE0) | (1<<PCIE1);
// ATmega328
// - PCIE0, PCIE1, PCIE2
// - PCMSK0, PCMSK1, PCMSK2
}
// SPI Transaction complete ISR
//
// This ISR is responsible for handling the read and write
// transfer cycles during a SPI transaction.
ISR(SPI_STC_vect)
{
// Local variables
uint8_t nBufDat = 0; // Storage for incoming SPDR
uint8_t nRegCmd = 0;
// ----------------------------------
// Capture inputs for previous cycle
// ----------------------------------
// Fetch the incoming data byte from the SPI Data Register
nBufDat = SPDR;
if (m_nXferCycle == 0) {
// COMMAND cycle
// Latch command
nRegCmd = nBufDat;
// Decode command
m_nRegAddr = (nRegCmd & 0x0F); // For now, only provide 16 regs
m_bRegRWb = (nRegCmd & 0xC0) >> 6;
// Perform range-check
// TODO: Handle the 16-bit read case
if (m_nRegAddr >= REG_MAX) {
// Disable write
m_nRegAddr = 0;
m_bRegRWb = 1;
}
} else if (m_nXferCycle == 1) {
// DATA cycle
// Latch data
if (m_bRegRWb == 0) {
// Write command: Latch write data
m_anRegArray[m_nRegAddr] = nBufDat;
} else {
// Read command: nothing to latch
}
} else if (m_nXferCycle == 2) {
// DATA cycle #2
if (m_bRegRWb == 0) {
// Write command: Latch write data
m_anRegArray[m_nRegAddr+1] = nBufDat;
}
}
// ----------------------------------
// Setup output for next cycle
// ----------------------------------
m_nXferCycle++;
if (m_nXferCycle > 3) {
m_bSpiXferOvf = 1;
}
// If we are still the selected slave, then proceed to
// define our outputs. Otherwise, we can ignore this
// request.
if (m_bSlaveSelected) {
if (m_nXferCycle == 1) {
// DATA cycle #1
// We only need to drive SPDR with valid data on a read
// but for efficiency, always return the current register value
SPDR = m_anRegArray[m_nRegAddr];
} else if (m_nXferCycle == 2) {
// DATA cycle #2
// For a 16-bit read, we advance the register address
// TODO: Consider adding array bounds checking here
SPDR = m_anRegArray[m_nRegAddr+1];
}
} else {
// We are not selected for next cycle
// The pin change int on SSb will be responsible
// for tristating the MISO pin so that other slaves
// can respond if they are selected.
}
}
// =================================
// Pin Change interrupt #0 ISR
//
// This ISR is responsible for monitoring the pins
// associated with I/O bank 0.
ISR(PCINT0_vect)
{
// ------------------------------------
// Start
// Latch the current pin values and deltas
uint8_t nPinValCur = PINA;
uint8_t nPinValChg = nPinValCur ^ m_nPinALast;
// Latch the current timestamp
//
// NOTE 1: By latching the timestamp once for all channels
// in the ISR, we are introducing timestamp error into the later
// channels. However, the tradeoff is against calling micros()
// multiple times which extends the ISR duration. If the ISR
// duration is too high, then there is a greater chance of SPI
// corruption due to the next SCLK edge arriving before we have
// completed this ISR and prepared for the next data in/out.
//
// NOTE 2: micros() is only accurate to approx 4us uncertainty.
// Other alternate timer implementations can increase this accuracy,
// but this code uses micros() to simplify the code.
uint16_t nCurTimeUs = micros();
// ------------------------------------
// Handler for SSb
if (nPinValChg & (1 << PORT_A_SS)) {
if (nPinValCur & (1 << PORT_A_SS)) { // rising edge
// SSb rising edge = deassertion
// - We are not currently selected
// - Release the bus
DDR_MISO_PORT &= ~(1 << DDR_MISO_FIELD); // pinMode(PIN_MISO,INPUT)
m_bSlaveSelected = false;
} else {
// SSb falling edge = assertion
// - We weren't selected before, but now are
// - Take ownership over the bus
DDR_MISO_PORT |= (1 << DDR_MISO_FIELD); // pinMode(PIN_MISO,OUTPUT)
// - Reset the transaction cycle
m_nXferCycle = 0;
m_bSlaveSelected = true;
}
}
// ------------------------------------
// Handler for CH5
if (nPinValChg & (1 << PORT_A_CH5)) {
if (nPinValCur & (1 << PORT_A_CH5)) { // rising edge
m_nPinRiseTimeUs[IND_CH5] = nCurTimeUs;
} else { // falling edge
m_anPulseUs[IND_CH5] = nCurTimeUs-m_nPinRiseTimeUs[IND_CH5];
m_nPulsesNew |= (1<<IND_CH5); // Indicate a new pulse
}
}
// ------------------------------------
// Handler for CH6
if (nPinValChg & (1 << PORT_A_CH6)) {
if (nPinValCur & (1 << PORT_A_CH6)) { // rising edge
m_nPinRiseTimeUs[IND_CH6] = nCurTimeUs;
} else { // falling edge
m_anPulseUs[IND_CH6] = nCurTimeUs-m_nPinRiseTimeUs[IND_CH6];
m_nPulsesNew |= (1<<IND_CH6); // Indicate a new pulse
}
}
// ------------------------------------
// Cleanup
// - Save the latest pin state
m_nPinALast = nPinValCur;
}
// Pin Change interrupt #1 ISR
//
// This ISR is responsible for monitoring the pins
// associated with I/O bank 1.
ISR(PCINT1_vect)
{
// ------------------------------------
// Start
// Latch the current pin values and deltas
uint8_t nPinValCur = PINB;
uint8_t nPinValChg = nPinValCur ^ m_nPinBLast;
// Latch the current timestamp
uint16_t nCurTimeUs = micros();
// ------------------------------------
// Handler for CH1
if (nPinValChg & (1 << PORT_B_CH1)) {
if (nPinValCur & (1 << PORT_B_CH1)) { // rising edge
m_nPinRiseTimeUs[IND_CH1] = nCurTimeUs;
} else { // falling edge
m_anPulseUs[IND_CH1] = nCurTimeUs-m_nPinRiseTimeUs[IND_CH1];
m_nPulsesNew |= (1<<IND_CH1); // Indicate a new pulse
}
}
// ------------------------------------
// Handler for CH2
if (nPinValChg & (1 << PORT_B_CH2)) {
if (nPinValCur & (1 << PORT_B_CH2)) { // rising edge
m_nPinRiseTimeUs[IND_CH2] = nCurTimeUs;
} else { // falling edge
m_anPulseUs[IND_CH2] = nCurTimeUs-m_nPinRiseTimeUs[IND_CH2];
m_nPulsesNew |= (1<<IND_CH2); // Indicate a new pulse
}
}
// ------------------------------------
// Handler for CH3
if (nPinValChg & (1 << PORT_B_CH3)) {
if (nPinValCur & (1 << PORT_B_CH3)) { // rising edge
m_nPinRiseTimeUs[IND_CH3] = nCurTimeUs;
} else { // falling edge
m_anPulseUs[IND_CH3] = nCurTimeUs-m_nPinRiseTimeUs[IND_CH3];
m_nPulsesNew |= (1<<IND_CH3); // Indicate a new pulse
}
}
// ------------------------------------
// Handler for CH4
// NOTE: This doesn't get called if USB bootloader active
if (nPinValChg & (1 << PORT_B_CH4)) {
if (nPinValCur & (1 << PORT_B_CH4)) { // rising edge
m_nPinRiseTimeUs[IND_CH4] = nCurTimeUs;
} else { // falling edge
m_anPulseUs[IND_CH4] = nCurTimeUs-m_nPinRiseTimeUs[IND_CH4];
m_nPulsesNew |= (1<<IND_CH4); // Indicate a new pulse
}
}
// ------------------------------------
// Cleanup
// - Save the latest pin state
m_nPinBLast = nPinValCur;
}
// =================================
// The main loop is responsible for the following operations:
// - Watchdog timeout: detects a lack of pulses on one or more
// RC channels (which indicates that the RC transmitter has
// been lost).
// - Updating RC pulse width registers which can be read via SPI.
// - Blinking a status LED to indicate if the transmitter link is
// active.
void loop() {
uint16_t nPulseUsWidth;
uint16_t nTimeMsCur;
uint16_t nTimeMsElapsed;
// Watchdog detector
for (int nChan=0;nChan<NUM_CHAN;nChan++) {
nTimeMsCur = millis();
if (m_nPulsesNew & (1<<nChan)) {
// New pulse detected in ISR
// Kick the watchdog
m_nPinKickTimeMs[nChan] = nTimeMsCur;
// Clear the timeout flag (if any)
m_nPulsesTimeout &= ~(1<<nChan);
// Reset the pulse detect
m_nPulsesNew &= ~(1<<nChan);
} else {
// No new pulse, so check watchdog limit
nTimeMsElapsed = nTimeMsCur-m_nPinKickTimeMs[nChan];
if (nTimeMsElapsed > PULSE_TIMEOUT) {
// Set the timeout flag
m_nPulsesTimeout |= (1<<nChan);
}
}
}
// Watchdog timeout -> Transmitter loss:
//
// If the RC transmitter is turned off (but the RC receiver
// is still powered up), then most channels will not contain
// pulses. However, some receivers (such as the Turnigy 9XCH8v2)
// will still output a stream of pulses on one or more channels.
// Therefore, the watchdog must only monitor certain channels
// for inactivity.
// - Only look at pulse train from CH1 & CH2
// - Note that Turnigy 9X8Cv2 seems to output very slow pulses
// on CH4 & CH5 during transmitter loss.
m_bTransmitterFail = 0;
if (m_nPulsesTimeout & ( (1<<IND_CH1) | (1<<IND_CH2) ) ) {
m_bTransmitterFail = 1;
}
// Store the pulses into the registers
for (int nChan=0;nChan<NUM_CHAN;nChan++) {
// Disable ints for 16b coherency
cli();
nPulseUsWidth = m_anPulseUs[nChan];
sei();
// Just report last saved pulse width. If there is a transmitter
// fail, then the status flag can be used as a failsafe.
m_anRegArray[REGBASE_CHAN+(nChan*REGS_PER_CHAN)+REG_PART_H] = nPulseUsWidth/256;
m_anRegArray[REGBASE_CHAN+(nChan*REGS_PER_CHAN)+REG_PART_L] = nPulseUsWidth%256;
} // nChan
// Now set overall status register
uint8_t nNewStatus;
nNewStatus = 0x00;
nNewStatus |= (m_bTransmitterFail)?(0x00):(0x80);
nNewStatus |= (m_bSpiXferOvf)?(0x00):(0x40);
cli();
m_anRegArray[REG_STATUS] = nNewStatus;
sei();
m_anRegArray[REG_RSVD1] = 0x00;
// Periodically flash the link status
#ifdef LED_FLASH
if (m_bTransmitterFail) {
setBlinkState(3);
} else {
setBlinkState(1);
}
doBlinkFsm();
#endif
}
// =================================
#define BLINK_FLASH_ON 20
#define BLINK_FLASH_OFF 150
enum teBlinkFsm {E_BLFSM_IDLE,E_BLFSM_ON,E_BLFSM_OFF};
volatile uint8_t nBlinkStatus = 0;
volatile uint8_t nBlinkRemain = 0;
volatile uint8_t eBlinkFsmState = E_BLFSM_IDLE;
volatile uint16_t nBlinkFsmTimeMsNxt = 0;
// Define the number of blinks to periodically flash
void setBlinkState(int nNum) {
nBlinkStatus = nNum;
}
// Update the LED status based on the blink FSM
// - The purpose of this blink routine is to be
// basically non-blocking. It relies upon defining
// timer thresholds for each stage of the blink
// request.
void doBlinkFsm() {
uint16_t nTimeMsCur = millis();
// Calculate next state
switch (eBlinkFsmState) {
case E_BLFSM_IDLE:
digitalWrite(PIN_LED,LOW);
if (nTimeMsCur > nBlinkFsmTimeMsNxt) {
if (nBlinkStatus > 0) {
eBlinkFsmState = E_BLFSM_ON;
nBlinkFsmTimeMsNxt = nTimeMsCur + BLINK_FLASH_ON;
nBlinkRemain = nBlinkStatus;
}
}
break;
case E_BLFSM_ON:
digitalWrite(PIN_LED,HIGH);
if (nTimeMsCur > nBlinkFsmTimeMsNxt) {
if (nBlinkRemain==0) {
// Should never get here
eBlinkFsmState = E_BLFSM_IDLE;
nBlinkFsmTimeMsNxt = nTimeMsCur + STATUS_TIMEOUT;
} else {
nBlinkRemain--;
eBlinkFsmState = E_BLFSM_OFF;
nBlinkFsmTimeMsNxt = nTimeMsCur + BLINK_FLASH_OFF;
}
}
break;
case E_BLFSM_OFF:
digitalWrite(PIN_LED,LOW);
if (nTimeMsCur > nBlinkFsmTimeMsNxt) {
if (nBlinkRemain==0) {
eBlinkFsmState = E_BLFSM_IDLE;
nBlinkFsmTimeMsNxt = nTimeMsCur + STATUS_TIMEOUT;
} else {
eBlinkFsmState = E_BLFSM_ON;
nBlinkFsmTimeMsNxt = nTimeMsCur + BLINK_FLASH_ON;
}
}
break;
}
}
// Flash the LED quickly [nNum] times
// - Blocking waits
void doBlinkFlash(int nNum) {
pinMode(PIN_LED, OUTPUT);
for (int i=0;i<nNum;i++) {
digitalWrite(PIN_LED,HIGH);
delay(20);
digitalWrite(PIN_LED,LOW);
delay(150);
}
}
// =================================