// Tactile5.ino // // Gerard Paresys // 10 9 2023 // // Utilise la library Adafruit_DRV2605 // Utilise la library Adafruit BusIO // // https://github.com/adafruit/Adafruit_DRV2605_Library/tree/master/examples/realtime // // OK Adafruit Feather M0 Radio + ADAFRUIT DRV2605L // // Pushbutton red from Pin 5 to ground // Pushbutton yellow from Pin 6 to ground // Pushbutton green from Pin 9 to ground // // the real-time playback mode allows the host processor to bypass the library playback engine // and play waveforms directly from the host through the I2C. // The real-time playback mode is a simple, single 8-bit register interface that holds an amplitude value. // When real- time playback is enabled, the real-time playback register is sent directly to the playback engine. // This value is played until the user sends the device to standby mode or removes the device from RTP mode. // The RTP mode operates exactly like the PWM mode except that the user enters a register value over the I2C // rather than a duty cycle through the input pin. // Therefore, any API (application-programming interface) designed for use with a PWM generator // in the host processor can write the data values over the I2C rather than writing the data values // to the host timer. // This ability frees a timer in the host while retaining compatibility with the original software. // For the LRA, the DRV2605 device automatically tracks the resonance frequency. // https://cdn-learn.adafruit.com/assets/assets/000/113/382/original/drv2605l.pdf // // http://adafruit.github.io/Adafruit_DRV2605_Library/html/class_adafruit___d_r_v2605.html #include #include "Adafruit_DRV2605.h" Adafruit_DRV2605 drv; const int buttonRedPin = 5; const int buttonYellowPin = 6; const int buttonGreenPin = 9; const int ledPin = 13; int buttonRedState = 0; // variable for reading the pushbutton status int buttonYellowState = 0; // variable for reading the pushbutton status int buttonGreenState = 0; // variable for reading the pushbutton status int buttonRedStateAncien = 0; // variable for reading the pushbutton status int buttonYellowStateAncien = 0; // variable for reading the pushbutton status int buttonGreenStateAncien = 0; // variable for reading the pushbutton status void setup() { Serial.begin(9600); drv.begin(); drv.setMode(DRV2605_MODE_REALTIME); // Set Real-Time Playback mode // drv.useERM(); // Use ERM (Eccentric Rotating Mass) mode. drv.useLRA(); // Use LRA (Linear Resonance Actuator) mode. pinMode(buttonRedPin, INPUT_PULLUP); // initialize the pushbutton pin as an input pinMode(buttonYellowPin, INPUT_PULLUP); // initialize the pushbutton pin as an input pinMode(buttonGreenPin, INPUT_PULLUP); // initialize the pushbutton pin as an input pinMode(ledPin, OUTPUT); drv.setRealtimeValue(0x00); // nul Serial.println("Sketch Tactile5.ino"); } void loop() { buttonRedState = digitalRead(buttonRedPin); // read the state of the pushbutton buttonYellowState = digitalRead(buttonYellowPin); // read the state of the pushbutton buttonGreenState = digitalRead(buttonGreenPin); // read the state of the pushbutton if (buttonRedState != buttonRedStateAncien) { if (buttonRedState == LOW) { drv.setRealtimeValue(0x7F); // Maxi digitalWrite(ledPin, HIGH); // LED on: } else { drv.setRealtimeValue(0x00); // nul digitalWrite(ledPin, LOW); // LED off: } buttonRedStateAncien = buttonRedState; Serial.print("buttonRed "); Serial.println(buttonRedState); } if (buttonYellowState != buttonYellowStateAncien) { if (buttonYellowState == LOW) { drv.setRealtimeValue(0x1F); // Moyen digitalWrite(ledPin, HIGH); // LED on: } else { drv.setRealtimeValue(0x00); // nul digitalWrite(ledPin, LOW); // LED off: } buttonYellowStateAncien = buttonYellowState; Serial.print("buttonYellow "); Serial.println(buttonYellowState); } if (buttonGreenState != buttonGreenStateAncien) { if (buttonGreenState == LOW) { drv.setRealtimeValue(0x0F); // Faible digitalWrite(ledPin, HIGH); // LED on: } else { drv.setRealtimeValue(0x00); // nul digitalWrite(ledPin, LOW); // LED off: } buttonGreenStateAncien = buttonGreenState; Serial.print("buttonGreen "); Serial.println(buttonGreenState); } delay(10); }