2016-07-27 1 views
0

닭고기 달걀 로커 "Incubator"를 건축 중입니다. Arduino 프로젝트를 처음 시도했지만 수년간 PLC를 프로그래밍했습니다. 나는 문제가있다 : 코드의 최상단 부분 (전환 할 때 홈 순서를 찾는다) 나는 달릴 수 없다. 그러나 컴파일한다. 나는 이것에서 길을 잃는다. 내가 어떤 문법을 놓친다면 확실하지 않다? 코드의 두 섹션이 PLS'c와 비슷하게 액세스 할 수 있지만 점프 (no goto) 명령임을 알기 위해 몇 가지 서브 루틴을 작성하려고합니다. 누군가가 기꺼이한다면 나는 어떤 방향으로 감사 할 것이다. 나는 포트 위치에 따라 리미트 스위치 타이머로 작동하는 업/다운 사이클 타이머를 가지고있다. 목표 : 홈 스위치를 켜면 시스템이 한계로 이동 한 후 집으로 이동하여 위치를 파악합니다. 이것은 부화장을 제거하기 위해 중간 단계에서 수행해야합니다 (트레이를 제거하려면 레벨/집이어야합니다). 나는 switch를보기 위해 while 명령을 사용하여이 코드 섹션을 유지할 수 있다고 생각했다. (스위치가 꺼질 때까지 집에서) 오른쪽으로 보이지 않는 추가 대괄호를 추가 할 때까지 확인 기능이 실패했지만 컴파일하고 보드에로드하십시오. 미리 감사드립니다. Adruino 초보자는 입력을 기반으로 조건부 동작을 만드는 방법을 알아 내려고합니다.

// breaking down the chicken code to find the bug 


int sensorPin = A0; // select the input pin for the potentiometer 
int ledPin = 13;  // the number of the LED pin 
int ledState = LOW; // ledState used to set the LED 
int sensorValue = 0; // variable to store the value coming from the sensor 
int homeswPin = 4;   // toggle sw for home sequence 
int homelimitswPin = 5;   // home limit sensor 
int timer = 0;   // variable to store timer 
int uplimitswPin = 2;  // up limit switch 
int dwnlimitswPin = 3;  // down limit switch 
int upoutputPin = 7;  // output to drive up 
int upoutput2Pin = 8;  // output to drive up 
int dwnoutputPin = 9;  // output to drive down 
int dwnoutput2Pin = 10;  // output to drive down 
long previousMillis = 0;  // will store last time LED was updated 
long interval = timer;  // interval at which to change 3519 x sensor value (milliseconds) 
long timedown = timedown;   // interval at which to change 3519 x sensor value (milliseconds 
unsigned long currentMillis = millis(); 

void setup() { // put your setup code here, to run once: 

    pinMode(ledPin, OUTPUT); 
    pinMode(homeswPin, INPUT_PULLUP); 
    pinMode(homelimitswPin, INPUT); 
    pinMode(uplimitswPin, INPUT); 
    pinMode(dwnlimitswPin, INPUT); 
    pinMode(upoutputPin, OUTPUT); 
    pinMode(dwnoutputPin, OUTPUT); 
    digitalWrite(7, HIGH); // +up safety stop motor 
    digitalWrite(8, HIGH); // -up safety stop motor 
    digitalWrite(9, HIGH); // + dwn safety stop motor 
    digitalWrite(10, HIGH); // - dwn safety stop motor 

} 


void loop() { 

    { // section 1 find home and stay there 
    while (digitalRead(homeswPin) == LOW); { 
    if // dont know where it is but need to find home or up limit 
    (digitalRead(homeswPin) == LOW && digitalRead(homelimitswPin) == HIGH && 
     digitalRead(uplimitswPin) == HIGH && digitalRead(dwnlimitswPin) == HIGH) { 
    // drives motor up 
    digitalWrite(upoutputPin, LOW); 
    } 
    // move until home or up limit switch found 
    else if 
    (digitalRead(homelimitswPin == LOW) || digitalRead(uplimitswPin == LOW)) { 
    //turn motor off 
    (digitalWrite(upoutputPin, HIGH)); 
    } 
    else if 
    // at up limit need to go home 
    (digitalRead(homeswPin) == LOW && digitalRead(uplimitswPin) == LOW) { 

    digitalWrite(dwnoutputPin, LOW); // drives motor down 
    //at home ? 
    digitalRead(homelimitswPin == HIGH); 

    digitalWrite(dwnoutputPin, HIGH); 
    } //turns motor off} 
    else if 
    // at down limit go home 
    (digitalRead(homeswPin) == LOW && digitalRead(dwnlimitswPin) == LOW) { 
    // drives motor up 
    digitalWrite(upoutputPin, LOW); 
    //at home 
    (digitalRead (homelimitswPin) == 0); 
    //turn motor off 
    digitalWrite(upoutputPin, HIGH); 
    } 
    else 
    // at home with home switch on stay here 
    (digitalRead(homeswPin) == LOW && digitalRead(homelimitswPin) == LOW); 
} 

} }

답변

0

는 sytax 오류를 코딩이 많이 있습니다. 다시 코드를 수정하려면 의사 코드를 작성할 수 있습니까? 코딩 구문은 PLC 시스템과 다릅니다. 코드가 어떻게 생겼는지 알려주세요. 예를 들어 변수 같은

을 사용

if digitalRead(homeswPin) == LOW) 
    // mention what are the action to be take including read and write function for digital pins 
if digitalRead(homeswPin) == HIGH) 
// whats your expected answers. 

더 나은 당신이 회로의 설계도를 넣어 그것. 나는 많은 루프 구멍을 발견했다. Arduino 기본 예제를 통해 잘 간다. digitalRead 함수를 사용하는 방법, 줄마다 arduino 코드를 디버깅하는 방법 기타

Examples found Here

관련 문제