Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int TRIG= PB3;
- const int ECHO = PB4;
- void setup() {
- pinMode(TRIG, OUTPUT);
- pinMode(ECHO, INPUT_PULLDOWN);
- attachInterrupt(ECHO, interrupt, CHANGE);
- Serial.begin(9600);
- }
- long time1 = 0;
- long time2 = 0;
- bool state = 0;
- void loop() {
- if(micros() - time1 > 1000000) //1 másodpercenként uj mérést kezd
- {
- digitalWrite(TRIG,HIGH);
- digitalWrite(TRIG,LOW);
- time1 = micros();
- }
- }
- void interrupt() {
- if(state)
- {
- time2=micros();
- }
- else
- {
- Serial.println((float)(micros() - time2)/1000000.0 * 170.0);
- }
- state = !state;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement