Created
September 20, 2021 04:23
-
-
Save RQF7/dc8d93615f64a535c3b18849f5751d57 to your computer and use it in GitHub Desktop.
Autonomus car with Cubelets
This file contains hidden or 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
#include "cubelet.h" | |
/** | |
* Sensor izquierdo: 88467 | |
* Sensor centro: 88373 | |
* Sensor derecho: 83755 | |
*/ | |
void setup() | |
{ | |
block_value = 0; | |
} | |
void loop() | |
{ | |
uint8_t centro = get_block_value(828618); | |
uint8_t izquierda = get_block_value(83755); | |
uint8_t derecha = get_block_value(88373); | |
/* Centro ocupado. */ | |
if (centro > 100) | |
{ | |
/* Izquierda ocupada. */ | |
if (izquierda < derecha) | |
{ | |
/* Girar a la derecha. */ | |
set_drive_direction(BACKWARD); | |
set_drive(255); | |
} | |
/* Izquierda libre. */ | |
else | |
{ | |
/* Girar a la izquierda. */ | |
set_drive_direction(FORWARD); | |
set_drive(255); | |
} | |
} | |
/* Sin obstáculos al centro. */ | |
else | |
{ | |
if (izquierda > 128 || derecha > 128) | |
{ | |
if (izquierda > derecha) | |
{ | |
/* Girar a la derecha. */ | |
set_drive_direction(BACKWARD); | |
set_drive(255); | |
} | |
else | |
{ | |
/* Girar a la izquierda. */ | |
set_drive_direction(FORWARD); | |
set_drive(255); | |
} | |
} | |
else | |
{ | |
/* Avanzar. */ | |
set_drive_direction(FORWARD); | |
set_drive(255); | |
} | |
} | |
wait(100); | |
} |
This file contains hidden or 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
#include "cubelet.h" | |
/** | |
* Sensor izquierdo: 88467 | |
* Sensor centro: 88373 | |
* Sensor derecho: 83755 | |
*/ | |
void setup() | |
{ | |
block_value = 0; | |
} | |
void loop() | |
{ | |
uint8_t centro = get_block_value(828618); | |
uint8_t izquierda = get_block_value(83755); | |
uint8_t derecha = get_block_value(88373); | |
/* Centro ocupado. */ | |
if (centro > 100) | |
{ | |
/* */ | |
if (izquierda < derecha) | |
{ | |
/* Girar a la derecha. */ | |
set_drive_direction(FORWARD); | |
set_drive(128); | |
} | |
/* Izquierda libre. */ | |
else | |
{ | |
/* Girar a la izquierda. */ | |
set_drive_direction(FORWARD); | |
set_drive(128); | |
} | |
} | |
/* Sin obstáculos al centro. */ | |
else | |
{ | |
if (izquierda > 128 || derecha > 128) | |
{ | |
if (izquierda > derecha) | |
{ | |
/* Girar a la derecha. */ | |
set_drive_direction(FORWARD); | |
set_drive(128); | |
} | |
else | |
{ | |
/* Girar a la izquierda. */ | |
set_drive_direction(FORWARD); | |
set_drive(128); | |
} | |
} | |
else | |
{ | |
/* Avanzar. */ | |
set_drive_direction(FORWARD); | |
set_drive(255); | |
} | |
} | |
wait(100); | |
} |
This file contains hidden or 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
#include "cubelet.h" | |
/** | |
* Sensor izquierdo: 83755 | |
* Sensor centro: 828618 | |
* Sensor derecho: 88373 | |
*/ | |
void setup() | |
{ | |
block_value = 0; | |
} | |
void loop() | |
{ | |
uint8_t centro = get_block_value(828618); | |
uint8_t izquierda = get_block_value(83755); | |
uint8_t derecha = get_block_value(88373); | |
/* Centro ocupado. */ | |
if (centro > 100) | |
{ | |
/* Izquierda ocupada. */ | |
if (izquierda < derecha) | |
{ | |
/* Girar a la derecha. */ | |
set_drive_direction(FORWARD); | |
set_drive(255); | |
} | |
/* Izquierda libre. */ | |
else | |
{ | |
/* Girar a la izquierda. */ | |
set_drive_direction(BACKWARD); | |
set_drive(255); | |
} | |
} | |
/* Sin obstáculos al centro. */ | |
else | |
{ | |
if (izquierda > 128 || derecha > 128) | |
{ | |
if (izquierda > derecha) | |
{ | |
/* Girar a la derecha. */ | |
set_drive_direction(FORWARD); | |
set_drive(255); | |
} | |
else | |
{ | |
/* Girar a la izquierda. */ | |
set_drive_direction(BACKWARD); | |
set_drive(255); | |
} | |
} | |
else | |
{ | |
/* Avanzar. */ | |
set_drive_direction(FORWARD); | |
set_drive(255); | |
} | |
} | |
wait(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.youtube.com/watch?v=Q5ueOMFNhwQ