Putting the MagTag to sleep is pretty easy, it's just a single line of code. Once you've imported the alarm module, you can put the MagTag into deep sleep (the other option is light sleep) with something like:

alarm.exit_and_deep_sleep_until_alarms(alarm)

The alarm parameter, which also comes from the alarm module, is one or more of several available alarm types:

  • time
  • pin
  • touch

The difference between these is the actual trigger source for the alarm. However, the general idea is the same with any of them - when the alarm condition is met, they wake up the MagTag from sleep.

For example, the time based alarm is very much like the alarms we humans use to wake up in the morning. We set a time and after it has elapsed, the alarm goes off. This is good for scheduling something to run at a certain time of the day. Checkout these projects for some example usages:

In this project we use the pin based alarm. This refers to an input pin on the processor and the alarm will trigger when the pin becomes HIGH (True) or LOW (False). This is analogous to you being woken up by a random noise instead of a time based alarm clock. The processor sleeps until this occurs, be it 5 seconds or 5 days.

Sources of Pin Change

The pin based alarm is general purpose. From the point of view of the processor, it only cares about the change in the pin state - like high or low. It does not care what actually caused that.

In this guide we'll look at two examples for generating a pin alarm:

  • button(s)
  • interrupt from external sensor (accelerometer)

Buttons are a good first example, since they are conceptually simple - you press a button and the pin changes. The sensor based interrupt is more complex since it requires the additional steps of properly configuring the sensor.

So....let's start with the simple button example.

This guide was first published on Jan 12, 2021. It was last updated on Jan 12, 2021.

This page (Pin Alarm Basics) was last updated on Jun 21, 2021.

Text editor powered by tinymce.