SHARE
TWEET

Untitled

a guest Jun 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pitches.h"
  2.  
  3. const byte trigPin = 3;  // pin "trig" branchée à la broche 5 de l'ATTiny85
  4. const byte echoPin = 5;  //pin "echo" branchée à la broche 6 de l'ATTiny85
  5. const byte DISTANCE_max=50;
  6. const byte Vout=6;
  7. byte volt_pwm=0;
  8. byte volt_pwm1=0;
  9. unsigned long t_millis=0;
  10.  
  11. void setup() {
  12.   pinMode(echoPin, INPUT);
  13.   pinMode(trigPin, OUTPUT);
  14.   pinMode(8, OUTPUT);
  15.   digitalWrite(trigPin, LOW);
  16.   Serial.begin(9600);
  17. }
  18.  
  19. void loop()
  20. {
  21.   long temps, distance;
  22.   digitalWrite(trigPin, HIGH);
  23.   delayMicroseconds(10);
  24.   digitalWrite(trigPin, LOW);
  25.  
  26.   temps = pulseIn(echoPin, HIGH);
  27.   distance = temps * 340/(2*10000);
  28.   Serial.println(distance);
  29.  
  30.   if(distance<=DISTANCE_max)
  31.   {
  32.   volt_pwm = map(distance, 0, DISTANCE_max, 170, 0);
  33.   analogWrite(Vout,volt_pwm);
  34.   if(millis()>t_millis+(800-pow(volt_pwm1,1.3)))
  35.   {
  36.    Serial.println(pow(volt_pwm1,1.3));
  37.    tone(8,1000+volt_pwm1*3,50);
  38.    t_millis=millis();
  39.    volt_pwm1=volt_pwm;
  40.   }
  41.  
  42.   }
  43.  
  44. else
  45.  analogWrite(Vout,0);
  46.  delay(100);
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top