SHARE
TWEET

Untitled

a guest Jan 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //rOBOT REMOTE BLUETOOTH 05
  2.  
  3. //#include <SoftwareSerial.h> //wajib pake kalau pin bluetooth tidak di 0 dan 1
  4.  
  5. //PIN BLUETOOTH RX,TX,0,1
  6. //our L298N control pins
  7. const int LeftMotorForward = 2;
  8. const int LeftMotorBackward = 3;
  9. const int RightMotorForward = 4;
  10. const int RightMotorBackward = 5;
  11.  
  12. const int e=9, f=8, g=7; //   e = bel, f,g  = flash & bel
  13. char val;
  14. void setup() {
  15.  
  16.   // Set L298N Control Pins as Output
  17.   pinMode(RightMotorForward, OUTPUT);
  18.   pinMode(LeftMotorForward, OUTPUT);
  19.   pinMode(LeftMotorBackward, OUTPUT);
  20.   pinMode(RightMotorBackward, OUTPUT);
  21.  
  22.   pinMode(e,OUTPUT);
  23.   pinMode(f,OUTPUT);
  24.   pinMode(g,OUTPUT);
  25.  
  26.   Serial.begin(9600);
  27. }
  28.  
  29. void maju()
  30. {
  31.  digitalWrite(RightMotorForward, HIGH);
  32.  digitalWrite(RightMotorBackward, LOW);
  33.  digitalWrite(LeftMotorForward, HIGH);
  34.  digitalWrite(LeftMotorBackward, LOW);
  35. }
  36.  
  37. void mundur()
  38. {
  39.  digitalWrite(RightMotorForward, LOW);
  40.  digitalWrite(RightMotorBackward, HIGH);
  41.  digitalWrite(LeftMotorForward, LOW);
  42.  digitalWrite(LeftMotorBackward, HIGH);
  43. }
  44.  
  45. void kanan()
  46. {
  47.  digitalWrite(RightMotorForward, LOW);
  48.  digitalWrite(RightMotorBackward, HIGH);
  49.  digitalWrite(LeftMotorForward, HIGH);
  50.  digitalWrite(LeftMotorBackward, LOW);
  51. }
  52.  
  53. void kiri()
  54.  
  55. {
  56.  digitalWrite(RightMotorForward, HIGH);
  57.  digitalWrite(RightMotorBackward, LOW);
  58.  digitalWrite(LeftMotorForward, LOW);
  59.  digitalWrite(LeftMotorBackward, HIGH);
  60. }
  61. void flskiri()
  62. {
  63.  digitalWrite(f,HIGH);delay(300);
  64.  digitalWrite(f,LOW);
  65. }
  66.  
  67. void flskanan()
  68. {
  69.  digitalWrite(g,HIGH);delay(300);
  70.  digitalWrite(g,LOW);
  71. }
  72.  
  73. void bel()
  74. {
  75.  digitalWrite(e,HIGH);delay(300);
  76.  digitalWrite(e,LOW);
  77. }
  78.  
  79. void off()
  80. {
  81.     digitalWrite(RightMotorForward,LOW);
  82.     digitalWrite(RightMotorBackward,LOW);
  83.     digitalWrite(LeftMotorForward,LOW);
  84.     digitalWrite(LeftMotorBackward,LOW);
  85.     digitalWrite(e,LOW);
  86.     digitalWrite(f,LOW);
  87.     digitalWrite(g,LOW);
  88.        
  89. }
  90.  
  91.  
  92. void loop() {
  93. if( Serial.available() >0 ) {
  94.     val = Serial.read();
  95.     Serial.println(val);
  96. }
  97.   if( val == '1' ) {
  98.     maju(); }
  99.   else if( val == '2' ) {
  100.     kiri(); }
  101.   else if( val == '3' ) {
  102.     mundur(); }
  103.   else if( val == '4' ) {
  104.     kanan(); }
  105.   else if( val == '5' ) {
  106.     bel(); }
  107.   else if( val == '6' ) {
  108.     flskiri(); }
  109.   else if( val == '7' ) {
  110.     flskanan();  
  111.  }
  112.   else if( val == 'A' ) {
  113.     off();
  114.     }
  115.   else if( val == 'B' ) {
  116.     off();    
  117.     }
  118.   else if( val == 'C' ) {
  119.     off(); }
  120.   else if( val == 'D' ) {
  121.     off(); }
  122.   else if( val == 'E' ) {
  123.     off(); }
  124.   else if( val == 'F' ) {
  125.     off(); }
  126.   else if( val == 'G' ) {
  127.     off();    
  128.   }
  129. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top