Last active
April 19, 2016 01:51
-
-
Save mfilipelino/3bf6b32c3e55898e4a3b63f169081cfa to your computer and use it in GitHub Desktop.
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
#define THRESHOLD 40 | |
struct ColorState { | |
int colorval; | |
unsigned int raw[]; | |
unsigned int norm[]; | |
int scaled[]; | |
}; | |
string debug_std_colors[] = { | |
"Black", "Blue", "Green", "Yellow", "Red", "White" | |
}; | |
string debug_color; | |
ColorState color_state; | |
mutex color_mutex; | |
void ReadColorSensor() { | |
Acquire(color_mutex); | |
ReadSensorColorEx(IN_3, | |
color_state.colorval, | |
color_state.raw, | |
color_state.norm, | |
color_state.scaled); | |
Release(color_mutex); | |
} | |
void PrintColorSensor() { | |
Acquire(color_mutex); | |
debug_color = debug_std_colors[color_state.colorval - 1]; | |
unsigned int red = color_state.norm[0]; | |
unsigned int green = color_state.norm[1]; | |
unsigned int blue = color_state.norm[2]; | |
Release(color_mutex); | |
TextOut(0, LCD_LINE1, debug_color, true); // true here will clear the screen | |
TextOut(0, LCD_LINE2, "red = " ); | |
NumOut (80, LCD_LINE2, red); | |
TextOut(0, LCD_LINE3, "green = " ); | |
NumOut (80, LCD_LINE3, green); | |
TextOut(0, LCD_LINE4, "blue = " ); | |
NumOut (80, LCD_LINE4, blue); | |
} | |
task color() { | |
while (true) { | |
ReadColorSensor(); | |
PrintColorSensor(); | |
} | |
} | |
task walk() | |
{ | |
bool reverte = false; | |
OnFwd(OUT_AC, 75); | |
int time = 75; | |
while (true) | |
{ | |
if (color_state.colorval == 6) | |
{ | |
if(reverte == false){ | |
OnRev(OUT_C, 75); | |
}else { | |
OnFwd(OUT_AC, 75); | |
OnRev(OUT_A, 75); | |
} | |
reverte = !reverte; | |
Wait(100); | |
while(color_state.colorval != 6){ | |
OnFwd(OUT_AC, 75); | |
Wait(100); | |
} | |
} | |
} | |
} | |
task main() { | |
SetSensorColorFull(IN_3); | |
Precedes(walk, color); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment