Hello!
I am using an Adafruit Circuit Playground Bluefruit (that's what I had lying around) to sense a tap and then generate pulses through a digital pin. I'm using the pin to control a motor through a MOSFET.
My problem is I cannot sense a change in voltage on the pin. My guess is that it may have something to do with the interrupt or the Circuit Playground libraries. I know the pin works because I tried the blink delay sketch, and that works. I also know that the ISR part works, because I can see the flag change appropriately.
In the code below, even if I comment out the entire ISR , I still can't get a response on the pin.
What am I doing wrong? Thank you!
#include <Arduino.h>
#include <Adafruit_Circuit_Playground.h>
#include <Wire.h>
#include <SPI.h>
// Adjust this number for the sensitivity of the 'click' force
// this strongly depend on the range! for 16G, try 5-10
// for 8G, try 10-20. for 4G try 20-40. for 2G try 40-80
#define CLICKTHRESHHOLD 10
const int motorPin = 6;
const int pulseDuration = 1000; // Duration of each pulse in milliseconds
const int pulseCount = 20; // Total number of pulses
const int buttonPin = 2; // Button connected to pin 2
volatile int flag = 0;
void setup(void) {
pinMode(motorPin, OUTPUT);
while (!Serial);
Serial.begin(9600);
CircuitPlayground.begin();
CircuitPlayground.setAccelRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 G!
// 0 = turn off click detection & interrupt
// 1 = single click only interrupt output
// 2 = double click only interrupt output, detect single click
// Adjust threshhold, higher numbers are less sensitive
CircuitPlayground.setAccelTap(1, CLICKTHRESHHOLD);
// have a procedure called when a tap is detected
attachInterrupt(digitalPinToInterrupt(CPLAY_LIS3DH_INTERRUPT), tapTime, FALLING);
}
void tapTime(void) {
flag = 1;
Serial.print("Flag Set");
}
void loop() {
if (flag) {
for (int i = 0; i < pulseCount; i++) {
// Turn on the motor
digitalWrite(motorPin, HIGH);
Serial.println("Set High");
// Delay for the pulse duration
delay(500);
// Turn off the motor
digitalWrite(motorPin, LOW);
Serial.println("Set Low");
// // Delay for the pulse duration
delay(500);
}
flag = 0;
}
}
This is my first time posting here, apologies if I'm making any mistakes. I would appreciate feedback on how to ask questions. Thanks!