Hallo Miteinander,
hier die Quelle für das Rechteck:
Code:
#include "asuro.h"
/***************************************************************************
* *
* This program is made for the ASURO Robot *
* *
* It draws a square. *
* *
***************************************************************************/
/***************************************************************************
* *
* 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. *
***************************************************************************/
/***************************************************************************
*
* void SetMotor(unsigned char left_speed, unsigned char right_speed );
*
* Range of speed: -7-0-7;
*
* function to control the motors
* Direction and speed can be set with on parameter
*
* Copyright: Stochri 2005
*
****************************************************************************/
unsigned char speedtable[8]={0,100,120,140,160,180,200,250};
void SetMotor(int leftspeed, int rightspeed )
{
unsigned char left,right;
if (leftspeed<0) left=RWD; // Test if leftspeed is negativ
else left=FWD;
if (leftspeed==0) left=BREAK;
if (rightspeed<0) right=RWD; // Test if leftspeed is negativ
else right=FWD;
if (rightspeed==0) right=BREAK;
leftspeed=abs(leftspeed);
rightspeed=abs(rightspeed);
if (leftspeed>7) leftspeed=7;
if (rightspeed>7) rightspeed=7;
MotorSpeed(speedtable[leftspeed],speedtable[rightspeed]);
MotorDir(left,right);
}
// delay in 1/10 seconds
void wait(int zehntel)
{
int i,temp2;
for(i=0;i<zehntel;i++)
for(temp2=0;temp2<100;temp2++) Sleep(72);
}
/***************************************************************************
*
* main
*
****************************************************************************/
#define zurueck {SetMotor(-6,-6);wait(7);};
#define links90grad {SetMotor(-2,2);wait(6);};
#define aus SetMotor(0,0);
int main(void)
{
Init();
wait(20);
StatusLED(YELLOW);
zurueck;
links90grad;
zurueck;
links90grad;
zurueck;
links90grad;
zurueck;
links90grad;
aus;
StatusLED(RED);
while(1)
{
StatusLED(RED);
wait(5);
StatusLED(GREEN);
wait(5);
}
return 0;
}
Lesezeichen