Minggu, 29 Mei 2016

Dasar Robot Servo

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 #include <Servo.h>

Servo myservo;
int pos = 0;
int xx=110; //nilai dirubah
int op=0;
int n,m2;
int t1=22; int t2=26; int t3=30;
int menu = 1;
String b,a,b2,a2;
void setup()
{
  lcd.begin(16, 2);
pinMode(t1,INPUT);
pinMode(t2,INPUT);
pinMode(t3,INPUT);
  myservo.attach(9);
  for(pos = 90; pos>op; pos-=1)  
  {                            
    myservo.write(pos);            
    delay(15);                    
  }
  b ="Pintu Tertutup";
delay(515);}

void loop()
{
  if (menu ==1) {
  if (digitalRead(t3)==1 ) menu=2;
  if (digitalRead(t2)==1 && pos != op) m2=1;
  if (digitalRead(t1)==1 && pos != xx) m2=2;
  if (m2==1 && pos!= op){
  myservo.write(pos);            
    delay(10);  pos -=1;
    a="Posisi " + String(pos);}

  if (m2==2 && pos!= xx){
  myservo.write(pos);            
    delay(10);  pos +=1;
    a="Posisi " + String(pos);;
  }
}
  if (menu ==2) {
   
      a= "Penyetingan Alat";delay (222);
   if (digitalRead(t3)==1 ) menu=1;
  }
  b=String(pos);
if (b2!=b || a2!=a ){ b2=b; a2=a;
 lcd.clear();
 lcd.setCursor(0, 0);lcd.print(a);
 lcd.setCursor(0, 1); lcd.print(b);
} }


Ide kreatip
Led berjalan dengan menggunakan for
Led berjalan dengan menggunakan if
While
Dahulu kala ketikadiharuskan
emrograman paskal. Seseorang diharuskan menguasai tahap demi tahapq





dari inkuator teknologi

#include <Servo.h>
Servo servo1; 
Servo servo2; 
Servo servo3; 
Servo servo4; 
Servo servo5;
unsigned int sudut;
String inString=””,temStr;
char str;
unsigned int nomor,l,i;
void setup()
{  
  Serial.begin(9600);  
  servo1.attach(2);//pin 2=servo1
  servo2.attach(3);//pin 3=servo2
  servo3.attach(4);//pin 4=servo3
  servo4.attach(5);//pin 5=servo4
  servo5.attach(6);//pin 6=servo5
  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90); 
  Serial.println(“ROBOT ARM CONTROLLER”);
 }
void loop()
{
 if(Serial.available()>0) 
   {    
      str = Serial.read();
      if(str!=’\n’)
        {  
          inString += (char)str;          
        }  
      else if (str == ‘\n’)      
        {                    
         temStr=inString.substring(0,1);
         nomor=temStr.toInt();
         temStr=inString.substring(2);
         sudut=temStr.toInt(); 
         Serial.print(nomor);
         Serial.print(” : “);
         Serial.println(sudut);
         switch(nomor){
            case 1:servo1.write(sudut); break;
            case 2:servo2.write(sudut); break;
            case 3:servo3.write(sudut); break;
            case 4:servo4.write(sudut); break;
            case 5:servo5.write(sudut); break;
         }          
         inString = “”;
        }
   }
}








Tidak ada komentar:

Posting Komentar