Created
December 19, 2011 09:10
-
-
Save Aluriak/1496225 to your computer and use it in GitHub Desktop.
NXC : Leopard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define Touch IN_1 | |
#define Tele IN_4 | |
#define Motors OUT_BC | |
#define PAS 7 | |
int vitesse = 50; | |
void setup() { | |
SetSensorTouch(Touch); | |
SetSensorLowspeed(Tele); | |
} | |
void recolle() { | |
// Cherche à s'approcher de la cible à +- 10cm | |
while(SensorUS(Tele) > 10) | |
{ | |
OnFwd(Motors, 100); | |
} | |
OnFwd(Motors, vitesse); | |
} | |
void follow() { | |
// Conserve la distance | |
if(SensorUS(Tele) <= 10) { | |
vitesse = vitesse -PAS; | |
} else { | |
vitesse = vitesse +PAS; | |
} | |
if(vitesse < 0) vitesse = 0; | |
if(vitesse > 100) vitesse = 100; | |
if(SensorUS(Tele) == NULL) vitesse = 0; | |
OnFwd(Motors, vitesse); | |
} | |
task main (){ | |
setup(); | |
recolle(); | |
while(1){follow();} | |
} | |
//*/ | |
/* LUCAS (le meilleurs) | |
#define Port_Tactile IN_1 | |
#define Port_Telemetre IN_2 | |
#define Port_Microphone IN_3 | |
#define PAS 10 | |
int vitesse = 50; | |
void setup() | |
{ | |
SetSensorTouch(IN_1); | |
SetSensorSound(IN_2); | |
SetSensorLowspeed(IN_4); | |
} | |
task main() | |
{ | |
setup(); | |
while(1) | |
{ | |
if(SensorUS(IN_4) > 10) vitesse += PAS; | |
else vitesse -= PAS; | |
if(vitesse < 0) vitesse = 0; | |
if(vitesse > 100) vitesse = 100; | |
OnFwd(OUT_BC, vitesse); | |
} | |
}//*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment