قسم الميكروكنترولر والروبوت ودوائر الاتصال بالحاسب الالي قسم المتحكمات الـ microcontroller و المعالجات microprocessor و التحكم الرقمي بالكمبيوتر CNC والانظمة الآلية والروبوت Robots

أدوات الموضوع

الصورة الرمزية mar7aba_01
mar7aba_01
:: مهندس متميز ::
تاريخ التسجيل: Jan 2010
الدولة: المغرب
المشاركات: 746
نشاط [ mar7aba_01 ]
قوة السمعة:0
قديم 25-01-2016, 03:04 AM المشاركة 1   
افتراضي ترجمة كود Twitter FaceBook Google+



السلام عليكم ورحمة الله
ياجماعة لو في مختص بلغة البايتون
محتاج لترجمة هذا الكود إلى البايتون وشكرا

كود:
String inputString = "";
String command = "";
String value = "";
String password = "arduPi"; // this is the password for opening and closing your door
                            // you can set any pasword you like using digit and symbols
boolean stringComplete = false; 


int motorPin1 = 10; // pin 2 on L293D IC
int motorPin2 = 11; // pin 7 on L293D IC
int motorEnablePin = 9; // pin 1 on L293D IC
int Speed = 150;

void setup(){
  //start serial connection
  Serial.begin(9600);  // baud rate is 9600 must match with bluetooth 
  //The String reserve() function allows you to allocate a buffer in memory for manipulating strings.
  inputString.reserve(50);  // reserve 50 bytes in memory to save for string manipulation 
  command.reserve(50);
  value.reserve(50);
  
  boolean stringOK = false;
  
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorEnablePin, OUTPUT);
  
}

void loop(){
  // if arduino receive a string termination character like \n stringComplete will set to true
  if (stringComplete) {
    //Serial.println(inputString);
    delay(100);
    // identified the posiion of '=' in string and set its index to pos variable
    int pos = inputString.indexOf('=');
    // value of pos variable > or = 0 means '=' present in received string.
    if (pos > -1) {
      // substring(start, stop) function cut a specific portion of string from start to stop
      // here command will be the portion of received string till '='
      // let received string is open=test123
      // then command is 'open' 
        command = inputString.substring(0, pos);
      // value will be from after = to newline command
      // for the above example value is test123
      // we just ignoreing the '=' taking first parameter of substring as 'pos+1'
      // we are using '=' as a separator between command and vale
      // without '=' any other character can be used
      // we are using = menas our command or password must not contains any '=', otherwise it will cause error 
        value = inputString.substring(pos+1, inputString.length()-1);  // extract command up to \n exluded
        //Serial.println(command);
        //Serial.println(value);
       
       // password.compareTo(value) compare between password tring and value string, if match return 0 
    if(!password.compareTo(value) && (command == "OPEN")){
          // if password matched and command is 'OPEN' than door should open
           openDoor(); // call openDoor() function
           Serial.println(" OPEN"); // sent open feedback to phone
           delay(100);
           }
    else if(!password.compareTo(value) && (command == "CLOSE")){
          // if password matched and command is 'CLOSE' than door should close
           closeDoor();
           Serial.println(" CLOSE"); // sent " CLOSE" string to the phone 
           delay(100);
           }
    else if(password.compareTo(value)){
          // if password not matched than sent wrong feedback to phone
           Serial.println(" WRONG");
           delay(100);
           } 
        } 
       // clear the string for next iteration
       inputString = "";
       stringComplete = false;
    }
   
}


void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read(); 
    //Serial.write(inChar);
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline or a carriage return, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n' || inChar == '\r') {
      stringComplete = true;
    } 
  }
}

void openDoor(){
   digitalWrite(motorPin1, HIGH);
   digitalWrite(motorPin2, LOW); 
   digitalWrite(motorEnablePin, HIGH);
   // use analogWrite() function if you want to control speed and use millis() function, not delay()
   //analogWrite(motorEnablePin, Speed);
   delay(1500); 
   // now off motor
   digitalWrite(motorPin1, LOW);
   digitalWrite(motorPin2, LOW);   
}

void closeDoor(){
   digitalWrite(motorPin1, LOW);
   digitalWrite(motorPin2, HIGH); 
   digitalWrite(motorEnablePin, HIGH);
   //analogWrite(motorEnablePin, Speed);
   delay(1500); 
   digitalWrite(motorPin1, LOW);
   digitalWrite(motorPin2, LOW); 

}
ولو في كود لبرمجة كود سري على الإبروم الداخلي للبيك 18ف4550
عبر TX-RX بلغة البايتون أكون شاكر لكم


التعديل الأخير تم بواسطة : mar7aba_01 بتاريخ 25-01-2016 الساعة 03:07 AM
اعلانات
إضافة رد

العلامات المرجعية

«     الموضوع السابق       الموضوع التالي    »
أدوات الموضوع

الانتقال السريع إلى


الساعة معتمدة بتوقيت جرينتش +3 الساعة الآن: 08:58 PM
موقع القرية الالكترونية غير مسؤول عن أي اتفاق تجاري أو تعاوني بين الأعضاء
فعلى كل شخص تحمل مسئولية نفسه إتجاه مايقوم به من بيع وشراء وإتفاق وأعطاء معلومات موقعه
التعليقات المنشورة لا تعبر عن رأي موقع القرية الالكترونية ولايتحمل الموقع أي مسؤولية قانونية حيال ذلك (ويتحمل كاتبها مسؤولية النشر)

Powered by vBulletin® Version 3.8.6, Copyright ©2000 - 2025