-
Fototrend
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
lanszelot
addikt
válasz
Tomika86 #20422 üzenetére
Először is köszönöm a segítséget mindenkinek.
Végre megértettem, amit próbáltatok elmagyarázni.
Rosszul értelmeztem amit írtatok.
Azt hittem a loop megvárja a szünetet, mert azt hittem az úgy működik mint a delay.
De nem, az úgy működik mint a beep.A loop végén írtam miert nem jó a hosszabb delay.
Akkor az egész eltorzul.Viszont az elsőbe ami nem jól működik oda beszúrtam egy delay-t.
És így, bár sufni tuning módra, de megoldódottitt a kész kód:
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
int trigPin = 40; // Trigger
int echoPin = 41; // Echo
long duration, cm, inches;
void setup() {
//Serial Port begin
Serial.begin (9600);
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Timer1.initialize();
MFS.initialize(&Timer1);
}
void loop() {
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// Convert the time into a distance
cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343
inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135
MFS.write((int)cm);
/*Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();*/
if (cm <= 30 && cm > 20) {
MFS.beep(25, // beep for 250 milliseconds
100, // silent for 1000 milliseconds
1, // repeat above cycle 1 times
1, // loop 1 times
1 // wait 10 milliseconds between loop
);
delay(320);
Serial.println("egyes");
}else if (cm <= 20 && cm > 10) {
MFS.beep(25, // beep for 250 milliseconds
10, // silent for 100 milliseconds
1, // repeat above cycle 1 times
1, // loop 1 times
1 // wait 10 milliseconds between loop
);
Serial.println("kettes");
}else if (cm <= 10) {
MFS.beep(55, // beep for 350 milliseconds
1, // silent for 10 milliseconds
1, // repeat above cycle 1 times
1, // loop 1 times
1 // wait 10 milliseconds between loop
);
Serial.println("harmas");
}
delay(320);
}
Új hozzászólás Aktív témák
- ASUS TUF F15 gamer laptop, i5-11400H, RTX 3050 Ti, makulátlan állapotban+ajándék
- SONY NEX-5N (SONY E bajonett)
- Samsung 870 QVO 8TB - keveset használt, 2026-ig garanciális - 100/100
- Garanciális // Lenovo Legion 5 // i9-14900HX // 32GB RAM // 1TB SSD // RTX 4070 // 240Hz
- Acer Predator Helios 16 // i7-13700HX // 32GB RAM // 1TB SSD // RTX 4070 // 240Hz
- Amazon Kindle 10th Generation ébresztős tok
- Apple iPhone 13 Pro 128GB, Kártyafüggetlen, 1 Év Garanciával
- Game Pass Ultimate előfizetés azonnal, élettartam garanciával, problémamentesen! Immáron 8 éve!
- Gamer PC-Számítógép! Csere-Beszámítás! R5 5600 / RX 6700XT 12GB / 16GB DDR4 / 500GB SSD
- GYÖNYÖRŰ iPhone 12 mini 128GB White-1 ÉV GARANCIA - Kártyafüggetlen, MS3469, 95% Akkumulátor
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest