PAL_MAG
OPEN-CLOSE SENSE PAL is used to acquire sensor values.
This ACT includes
Sending and receiving wireless packets
Configuring settings via Interactive settings mode - <STG_STD>
State transition control by state machine - <SM_SIMPLE>
ACT functions
Uses the OPEN-CLOSE SENSE PAL to interrupt and wake up when the magnetic sensor is detected and transmit wirelessly.
Uses the sleep function to operate on coin cell batteries.
How to use ACT
Required TWELITE
Parent Node
MONOSTICK BLUE or RED Act Parent_MONOSTICK in action.
Child Node
Explanation of ACT
Include
Board BEHAVIOR for open/close sensor pal <PAL_MAG>
is included.
setup()
First, register the board behavior <PAL_MAG>
. When the board behavior is initialized, the sensors and DIOs are initialized. The reason for doing this first is that it is common to check the status of the board's DIP SW, etc., and then configure the network settings and so on.
Here, 3 bits of the 4-bit DIP SW on the board are read and set as the ID of the Child Node; if 0, the Child Node without ID (0xFE
) is assumed.
Set the LED settings. Here the ON/OFF blinking is set to blink every 10ms (in an application that sleeps and has a short wake-up time, this is almost equivalent to setting the LED to turn on during wake-up).
begin()
The begin()
function exits the setup()
function (after which TWENET is initialized) and is called just before the first loop()
.
Call sleepNow()
after setup()
ends to perform the first sleep.
sleepNow()
Before going to sleep, set the interrupt for the DIO pin of the magnetic sensor. Use pinMode()
, the second parameter is PIN_MODE::WAKE_FALLING
. This is a setting to wake up when the pin state changes from HIGH to LOW.
In line 7, the_twelite.sleep()
executes sleep. The parameter 60000 is the wake-up setting required to reset the watchdog on the TWELITE PAL board. If not reset, a hard reset will be performed after 60 seconds.
wakeup()
When the program wakes up from sleep, wakeup()
is called. After that, loop()
is called each time. Before wakeup()
, each peripheral such as UART and devices on the board are woken up (e.g. resetting the watchdog timer). For example, it restarts the LED lighting control.
Here, in the case of wake-up from the wake-up timer (the_twelite.is_wokeup_by_wktimer()
), sleep is performed again. This is a wake-up only for the purpose of resetting the watchdog timer described above.
In the case of wakeup upon detection of the magnetic sensor, the loop() process will continue.
loop()
Here, the DIO of the detected magnetic sensor is checked, packets are sent, and sleep is performed again after packet transmission is complete.
The b_transmit
variable controls the behavior within loop()
. After a successful transmission request, this value is set to 1, and the program waits for the packet transmission to complete.
Check the detection DIO pins of the magnetic sensor. There are two types of detection pins: N-pole detection and S-pole detection. If you simply want to know that a magnet is approaching, you need to know that one of the pins has been detected.
Use the_twelite.is_wokeup_by_dio()
to check the pin of the wakeup factor. The parameter is the pin number. The reason why the return value is stored in uint8_t is to store it in the payload of the packet.
After setting communication conditions and storing data in the payload, transmission is performed.
Then, if b_transmit
is true
during loop()
, a completion check is performed, and if completed, sleepNow()
puts the program to sleep.
The completion of transmission is confirmed by the_twelite.tx_status.is_complete(u8txid)
. The u8txid
is the ID value returned on transmission.
最終更新