Commit c65f3408 authored by sonaraju's avatar sonaraju
Browse files

Delete haptic.ino

parent cba89982
#include <Adafruit_DRV2605.h>
Adafruit_DRV2605 drv;
// defines pins numbers
//A4 SCA
//A5 SLC
const int trigPin = 5;
const int echoPin = 4;
const int ledPin = 3;
unsigned long time_now = 0;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts the serial communication
drv.begin();
// I2C trigger by sending 'go' command
drv.setMode(DRV2605_MODE_INTTRIG); // default, internal trigger when sending GO command
drv.selectLibrary(1);
drv.setWaveform(1, 1); // strong click 100%, see datasheet part 11.2
drv.setWaveform(2, 0); // end of waveforms
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration*0.034/2;
if(distance < 50) {
digitalWrite(ledPin, HIGH);
Serial.println(distance);
delay(distance * 15);
digitalWrite(ledPin, LOW);
drv.go();
delay(distance * 15);
}
else {
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(300);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment