10/29/20 12:23
Dependencies: mbed DRV2605 HCSR04 HC_SR04_Ultrasonic_Library
Diff: main.cpp
- Revision:
- 2:35ef0b31a857
- Parent:
- 1:fbdfdb9ecbd2
- Child:
- 3:ab0d9d3ae4d4
diff -r fbdfdb9ecbd2 -r 35ef0b31a857 main.cpp --- a/main.cpp Fri Oct 30 19:24:27 2020 +0000 +++ b/main.cpp Fri Oct 30 21:03:24 2020 +0000 @@ -8,7 +8,10 @@ //DRV2605 haptics(p9, p10); - +I2C i2c1(p9, p10); +I2C i2c2(p28, p27); +DRV2605 hap1(&i2c1); +DRV2605 hap2(&i2c2); Timeout cycle; @@ -19,25 +22,36 @@ //two calls to this interrupt routine generates a square wave void toggle_interrupt() { - if (half_cycle_time>22000) haptics.play_waveform(0); + if (distance > 10) { + hap1.setWaveform(0); + hap1.playRtp(10); + } else if (distance > 50) { + hap1.seWaveform(0); + hap1.playRtp(50); + } + + /*if (half_cycle_time>22000) haptics.play_waveform(0); else { static int e1 = 1; haptics.play_waveform(e1); e1+=10; if(e1 > 121) e1 = 1; } - led = !led; + led = !led;*/ cycle.detach(); //update time for interrupt activation -change frequency of square wave cycle.attach_us(&toggle_interrupt, half_cycle_time); } + +/* void newdist(int distance) { //update frequency based on new sonar data led2 = !led2; half_cycle_time = distance<<3; } +*/ //HC-SR04 Sonar module ultrasonic mu(p7, p8, .07, 1, &newdist); //Set the trigger pin to p6 and the echo pin to p7