Video:
Program:
int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver pinMode(2,OUTPUT); // kendali motor 1 pinMode(3,OUTPUT); // motor 1 + pinMode(4,OUTPUT); // motor 1 - pinMode(5,OUTPUT); // kendali motor 2 pinMode(6,OUTPUT); // motor 2 + pinMode(7,OUTPUT); // motor 2 - } void kanan(void){ digitalWrite(2,LOW); digitalWrite(5,LOW); delayMicroseconds(100); digitalWrite(3,HIGH); digitalWrite(4,LOW); delayMicroseconds(100); digitalWrite(6,LOW); digitalWrite(7,HIGH); delayMicroseconds(100); digitalWrite(2,HIGH); digitalWrite(5,HIGH); delayMicroseconds(200); } void kiri(void){ digitalWrite(2,LOW); digitalWrite(5,LOW); delayMicroseconds(100); digitalWrite(3,LOW); digitalWrite(4,HIGH); delayMicroseconds(100); digitalWrite(6,HIGH); digitalWrite(7,LOW); delayMicroseconds(100); digitalWrite(2,HIGH); digitalWrite(5,HIGH); delayMicroseconds(200); } void maju(void){ digitalWrite(2,LOW); digitalWrite(5,LOW); delayMicroseconds(100); digitalWrite(3,LOW); digitalWrite(4,HIGH); delayMicroseconds(100); digitalWrite(6,LOW); digitalWrite(7,HIGH); delayMicroseconds(100); digitalWrite(2,HIGH); digitalWrite(5,HIGH); delayMicroseconds(200); } void mundur(void){ digitalWrite(3,HIGH); digitalWrite(4,LOW); delayMicroseconds(100); digitalWrite(6,HIGH); digitalWrite(7,LOW); delayMicroseconds(100); digitalWrite(2,HIGH); digitalWrite(5,HIGH); delayMicroseconds(200); } void henti(void){ // berhenti digitalWrite(3,LOW); digitalWrite(4,LOW); delayMicroseconds(100); digitalWrite(6,LOW); digitalWrite(7,LOW); delayMicroseconds(100); digitalWrite(2,LOW); digitalWrite(5,LOW); delayMicroseconds(200); } void loop() { if (irrecv.decode(&results)) { if((results.value)== 2049||(results.value)== 1){ maju(); delay(10); } if((results.value)== 2052||(results.value)== 4){ kiri(); delay(10); } if((results.value)== 2053||(results.value)== 5){ henti(); delay(10); } if((results.value)== 2054||(results.value)== 6){ kanan(); delay(10); } if((results.value)== 2057||(results.value)== 9){ mundur(); delay(10); } irrecv.resume(); // Receive the next value } }
Tidak ada komentar:
Posting Komentar