Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <NewPing.h>
- #include <IRremote.h>
- int wartosc = 0x0;
- IRsend irsend;
- #define trig 12
- #define echo 11
- #define max_dyst 30
- #define r 6
- #define y 5
- #define g 4
- NewPing sonar(trig,echo,max_dyst);
- void setup() {
- Serial.begin(115200);
- pinMode(trig,OUTPUT);
- pinMode(echo,INPUT);
- }
- void loop() {
- int odleglosc = sonar.convert_cm(sonar.ping_median());
- if (odleglosc<10 && odleglosc!=0) {
- digitalWrite(g,LOW);
- digitalWrite(y,LOW);
- digitalWrite(r,HIGH);
- Serial.println("wstecz");
- irsend.sendRC5(0x61, 12);
- wartosc = 0x61;
- delay(5000); //In this example, the signal will be repeated every 5 seconds, approximately.
- }
- else if (odleglosc>20) {
- digitalWrite(g,HIGH);
- digitalWrite(y,LOW);
- digitalWrite(r,LOW);
- Serial.println("do przodu");
- irsend.sendRC5(0x60, 12);
- wartosc = 0x60;
- delay(5000);
- }
- else if (odleglosc>=10 && odleglosc<=20){
- digitalWrite(g,LOW);
- digitalWrite(y,HIGH);
- digitalWrite(r,LOW);
- Serial.println("nic");
- wartosc = 0x0;
- delay(100);
- }
- else {
- Serial.println("stara wartosc");
- Serial.println(wartosc);
- irsend.sendRC5(wartosc,12);
- delay(2000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement