Created
March 10, 2025 14:07
-
-
Save rdlauer/4877247536c7add499f1960119bd8e14 to your computer and use it in GitHub Desktop.
Notecard ATTN Guide on Swan and Notecarrier F
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <Notecard.h> | |
// define IRAM_ATTR for compatibility with STM32 | |
#ifndef IRAM_ATTR | |
#define IRAM_ATTR | |
#endif | |
#define usbSerial Serial | |
Notecard notecard; | |
volatile bool notecard_request_to_arm = false; | |
void IRAM_ATTR armInterrupt() | |
{ | |
// Take no action when already armed | |
if (digitalRead(D5)) | |
{ | |
notecard_request_to_arm = true; | |
usbSerial.println("INFO: ATTN interrupt armed!"); | |
} | |
} | |
void IRAM_ATTR attention() | |
{ | |
// Visualize the attention pin state | |
digitalWrite(LED_BUILTIN, digitalRead(D5)); | |
} | |
void setup() | |
{ | |
delay(1000); | |
usbSerial.begin(115200); | |
notecard.setDebugOutputStream(usbSerial); | |
// Initialize Notecard | |
notecard.begin(); | |
// Attach Notecard Interrupt | |
pinMode(D5, INPUT); | |
attachInterrupt(digitalPinToInterrupt(D5), attention, RISING); | |
// Attach Button Interrupt | |
pinMode(USER_BTN, INPUT_PULLUP); | |
attachInterrupt(digitalPinToInterrupt(USER_BTN), armInterrupt, RISING); | |
// Debug LED (mirrors `ATTN`) | |
pinMode(LED_BUILTIN, OUTPUT); | |
digitalWrite(LED_BUILTIN, digitalRead(D5)); | |
} | |
void loop() | |
{ | |
// Process arming request | |
if (notecard_request_to_arm) | |
{ | |
notecard_request_to_arm = false; | |
// Arm ATTN Interrupt | |
J *req = NoteNewRequest("card.attn"); | |
if (req) | |
{ | |
JAddStringToObject(req, "mode", "arm"); | |
JAddNumberToObject(req, "seconds", 3); | |
if (notecard.sendRequest(req)) | |
{ | |
// Visualize the attention pin state | |
digitalWrite(LED_BUILTIN, digitalRead(D5)); | |
} | |
else | |
{ | |
usbSerial.println("ERROR: Failed to arm ATTN interrupt!"); | |
} | |
} | |
} | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment