Codeiteruoperwtu

// YEU SANG TAO - YST-DIY - SANG TAO DE THANH CONG !!!

#include <Servo.h>
#include <EEPROM.h>
#define trig 7
#define echo 6
#define BUZZER 4
#define RDIR 12 // chiều quay động cơ phải
#define RPWM 11 // tốc độ động cơ phải
#define LDIR 13 // chiều quay động cơ trái
#define LPWM 10 // tốc độ động cơ trái
int RF_speed = 0;
void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);

pinMode(RDIR, OUTPUT); //Chan LDIR la ngo ra dieu khien chieu dong co trai
pinMode(LDIR, OUTPUT); //Chan RDIR la ngo ra dieu khien chieu dong co phai
digitalWrite(RPWM, LOW); //Chan RDIR o muc thap (0v)
digitalWrite(LPWM, LOW);

for(int i = 2000; i< 3500; i += 500)
{
tone(BUZZER, i ,100);
delay(100);

//pinMode (xuat, OUTPUT);

}
Serial.begin (9600);
}
int CB_sieu_am()
{
int Sieu_am;
int time;
digitalWrite(trig,0); // tắt chân trig
delayMicroseconds(200);
digitalWrite(trig,1); // bật chân trig
delayMicroseconds(50);
digitalWrite(trig,0);
time = pulseIn (echo,HIGH); // hàm pulseIn (http://arduino.vn/reference/pulsein)
Sieu_am =0.0344*(time/2); //tính khoánh cách đến vật thể
return Sieu_am; // http://arduino.vn/reference/return
Serial.println(Sieu_am);
Serial.println(“CM”);
}
void trang_thai_khong_vat_can()
{
int b=(CB_sieu_am());
EEPROM.write(9,b); // EEPROM có 512 ô nhớ từ 0-511
delay(10);
if(EEPROM.read(9)>20)
{
Serial.println("------(khong co vat can)------");
tien();
}

}
void trang_thai_co_vat_can(){
int b=(CB_sieu_am());
EEPROM.write(9,b); // EEPROM có 512 ô nhớ từ 0-511
delay(10);

if (EEPROM.read(9)<20)
{
delay(50);
Serial.println("------(co vat can)-------");
dung();
delay(1000);
lui();
delay(400);
dung();
delay(500);
trai();
delay(400);
dung();
delay(500);
int c=(CB_sieu_am());
EEPROM.write(10,c); // EEPROM có 512 ô nhớ từ 0-511
delay(10);
if(EEPROM.read(10)>20){
trang_thai_khong_vat_can();
}
else if (EEPROM.read(10)<20){
trang_thai_co_vat_can();
}
}
}
void tien(){
analogWrite(LPWM, 70);
digitalWrite(LDIR, LOW);
analogWrite(RPWM, 70);
digitalWrite(RDIR, HIGH);
}
void lui() {
analogWrite(LPWM, 99);
digitalWrite(LDIR, HIGH);
analogWrite(RPWM, 90);
digitalWrite(RDIR, LOW);
}
void trai() {
analogWrite(LPWM, 85);
digitalWrite(LDIR, LOW);
analogWrite(RPWM, 85);
digitalWrite(RDIR, LOW);
}

void dung() {
analogWrite(LPWM,0);
digitalWrite(LDIR, LOW);
analogWrite(RPWM,0);
digitalWrite(RDIR, LOW);
}

void loop() {
trang_thai_khong_vat_can();
trang_thai_co_vat_can();
CB_sieu_am();
}

Hi there

I doubt there are many users here who speak/read/write Vietnamese but hopefully someone can help you. I couldn’t make out what your question is. Google translated your message “YEU SANG TAO - YST-DIY - SANG TAO DE THANH CONG” to “YEU PEOPLE - YST-DIY - PEOPLE DE THANH CONG” which really didn’t help me understand it at all. :frowning:

Could you edit your Arduino links please - they appear to link to facebook rather than the advertised Arduino URLs.