- fchao-Sinus-Wechselrichter AliExpress         
Ergebnis 1 bis 5 von 5

Thema: PollSwitch() Problem

Baum-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #2
    Moderator Robotik Visionär Avatar von radbruch
    Registriert seit
    27.12.2006
    Ort
    Stuttgart
    Alter
    62
    Beiträge
    5.799
    Blog-Einträge
    8
    Hallo

    Versuche es mal so:

    Code:
    /************************************************** *************************
    * *
    * This program is free software; you can redistribute it and/or modify *
    * it under the terms of the GNU General Public License as published by *
    * the Free Software Foundation; either version 2 of the License, or *
    * any later version. *
    ************************************************** *************************/
    
    #include <asuro.h>
    
    void sleep_ms(int ms)
    {
    	while(ms>0)
    	{
    		Sleep(72);
    		ms=ms-1;
    	}
    }
    
    void hindernis_rechts(void)
    {
    	MotorDir(BREAK,BREAK);
    	MotorSpeed(0,0);
    	sleep_ms(2000);
    	FrontLED(OFF);
    	StatusLED(YELLOW);
    	BackLED(ON,ON);
    	MotorDir(FWD,FWD);
    	MotorSpeed(100,50);
    	sleep_ms(2000);
    	BackLED(OFF,OFF);
    	MotorDir(BREAK,BREAK);
    	MotorSpeed(0,0);
    	sleep_ms(5000);
    }
    
    void hindernis_links(void)
    {
    	MotorDir(BREAK,BREAK);
    	MotorSpeed(0,0);
    	sleep_ms(2000);
    	FrontLED(OFF);
    	StatusLED(YELLOW);
    	BackLED(ON,ON);
    	MotorDir(FWD,FWD);
    	MotorSpeed(50,100);
    	sleep_ms(2000);
    	BackLED(OFF,OFF);
    	MotorDir(BREAK,BREAK);
    	MotorSpeed(0,0);
    	sleep_ms(5000);
    }
    
    int main (void){
    	unsigned int Switch1, Switch2;
    	Init();
    	Switch2=PollSwitch();
    	while(1)
    	{
    		FrontLED(ON);
    		StatusLED(GREEN);
    		MotorDir(RWD,RWD);
    		MotorSpeed(175,175);
    		Switch1=PollSwitch();
    		if ((Switch1 == Switch2) && (Switch1 != 0))
    		{
    			StatusLED(RED);
    			if(Switch1<=7)
    			{
    				BackLED(OFF,ON);
    				hindernis_rechts();
    			}
    			else
    			{
    				BackLED(ON,OFF);
    				hindernis_links();
    			}
    		}
    		else
    			BackLED(OFF,OFF);
    
    		Switch2=Switch1;
    	}
    }
    (ungetestet)

    Änderungen:

    main()-Aufrufe am Ende der Ausweichfunktionen entfernt. else-Zweig in Klammern gesetzt:

    else
    {
    BackLED(ON,OFF);
    hindernis_links();
    }

    und Mehrfachabfrage von PollSwitch() eingefügt.

    Gruß

    mic
    Geändert von radbruch (08.03.2013 um 18:40 Uhr) Grund: Kosmetik im Quellcode
    Bild hier  
    Atmel’s products are not intended, authorized, or warranted for use
    as components in applications intended to support or sustain life!

Ähnliche Themen

  1. PollSwitch tast/programmier problem
    Von SRT im Forum Asuro
    Antworten: 4
    Letzter Beitrag: 02.02.2008, 14:41
  2. Antworten: 8
    Letzter Beitrag: 30.04.2007, 10:15
  3. Problem mir "PrintInt(PollSwitch())"
    Von Rob.Anfänger im Forum Asuro
    Antworten: 5
    Letzter Beitrag: 05.02.2007, 17:50
  4. pollSwitch
    Von The-BooN- im Forum Asuro
    Antworten: 11
    Letzter Beitrag: 01.12.2006, 09:41
  5. [Asuro] Problem bei Tasterabfrage mittels PollSwitch
    Von jenser212 im Forum C - Programmierung (GCC u.a.)
    Antworten: 20
    Letzter Beitrag: 30.01.2006, 15:27

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

Labornetzteil AliExpress