Please can you help me create arduino code for my project. I am able to pay you for your time as I cannot proceed much further with it, without some advanced help.
My components
-ADAFRUIT FLORA V3 (Atmega32u4 chip)
-DRV2605L haptic driver
-pancake vibrating motor
-3 buttons
-Lipoly 3.6v battery
My project requires 3No haptic vibrations, depending upon which button is pressed. Button 1: 10 second haptic vibration triggered then stop. Button 2: 2 min haptic then stop. Button 3 10 min haptic then stop. Please see diagram.
I have followed the "Adafruit haptic headband" tutorial, which works fine. Is it possible to add additional code to enable these three button inputs at all? I have searched the forum and elsewhere but I am confused regarding analogue vs digital buttons. Where to connect these buttons. Even if this is possible. Floating buttons confuse me too (but shouldnt be a problem?!). I'm not from a computing background, but I have tried my best so far. If you can lend a hand please let me know your rates etc via DM on post here please. Thank you. http://https://learn.adafruit.com/haptic-headband/solder-circuit
I don't have the DRV2605L Haptic Motor Controller and never used their module, but based on what I read in the code it seems pretty trivial to do something crude
#include <Wire.h>
#include <Adafruit_DRV2605.h>
Adafruit_DRV2605 drv;
const byte b1Pin = 10;
const byte b2Pin = 9;
const byte b3Pin = 6;
const uint32_t oneSecond = 1000ul; // 1000 ms in one second
const uint32_t oneMinute = oneSecond * 60ul; // 60 seconds is one minute
const uint32_t b1Delay = oneSecond * 10ul; // 10 seconds
const uint32_t b2Delay = oneMinute * 2ul; // 2 minutes
const uint32_t b3Delay = oneMinute * 10ul; // 10 minutes
// default effect = 7 --> Soft Bump - 100%
// call is BLOCKING.
// see https://github.com/adafruit/Adafruit_DRV2605_Library/blob/master/examples/basic/basic.ino for list of effects
void playEffect(const uint32_t duration, const uint8_t effect = 7)
{
drv.setWaveform(0, effect); // play effect
drv.setWaveform(1, 0); // end waveform
drv.go(); // assuming this repeat the effect until being told to stop
delay(duration);
drv.stop();
}
void setup() {
pinMode(b1Pin, INPUT_PULLUP);
pinMode(b2Pin, INPUT_PULLUP);
pinMode(b3Pin, INPUT_PULLUP);
drv.begin();
drv.selectLibrary(1);
drv.setMode(DRV2605_MODE_INTTRIG);
}
void loop() {
if (digitalRead(b1Pin) == LOW) playEffect(b1Delay); // button 1 pressed
else if (digitalRead(b2Pin) == LOW) playEffect(b2Delay); // button 2 pressed
else if (digitalRead(b3Pin) == LOW) playEffect(b3Delay); // button 3 pressed
}
Note that this is blocking code. So as soon as you press one of the button the motor will start vibrating and there is no way to stop besides pressing reset or powering off the board.
it would not be super difficult to make it non blocking - leaving that as an exercise
this is assuming that drv.go() repeats the effect until being told to stop(); if it does not work (only play the effect once) then replace the function with
void playEffect(const uint32_t duration, const uint8_t effect = 7)
{
uint32_t t0 = millis();
drv.setWaveform(0, effect); // play effect
drv.setWaveform(1, 0); // end waveform
while (millis() - t0 < duration) drv.go(); // repeat until timeout
drv.stop();
}