Today I started the VEX programming. In a very short time, I was able do simple robotics manuever code. Most importantly, I got to do functions. I was able to measure and modularize my algorithm and program the bot to manuever through the maze, roughly without the encoder. Then using the encoder, the robot move more accurately and got into the box, the very first time!!! But no one was around to see it. Then everyone shows up to see it the second time but the battery was low so it didn't perform as well. I believe Shawn or Brian has the video.
'Color Sensor LeDs RGB on outputs 1,2,3 USING PWM
'Read the CDs cell on ADC 4
Low 0,1,2,3,4,5 'Set all outputs to low to turn off RGB
pause 1000
main:
w3 = 0 'This is the sum of all channels
high 1 'Set the RED channel high turns it on
low 2,3
pause 50 'Give time for the LED to turn on
readadc 0,b0 'Read the value from the LDR
high 3 'Set the BLUE Channel ON
low 1,2
pause 50
readadc 0,b2 'Read the value from the LDR into a different variable
'Apply any necessary offset for the sensitivity of the LDR
high 2 'Repeat for the GREEN Channel
low 1,3
pause 50
readadc 0,b1
b1 = b1 - 30
debug
w3 = b0 + b1 + b2 'Find the sum of the 3 color channels
'sertxd ("w3 reading ",#w3,13,10)
if w3 > 510 then nocolor 'Cut on total intensity
if w3 < class="Apple-tab-span" style="white-space:pre"> 'Cut on total intensity
if b0>b1 and b0>b2 then red
if b1>b0 and b1>b2 then green
if b2>b0 and b2>b1 then blue
goto main
nocolor:
sertxd ("nocolor",13,10)
pwmout 2,99,400 ;SET THE OUTPUT TO 5V
low 4,5
goto main
red:
sertxd ("red",13,10)
pwmout 2,99,0 ;SET THE OUTPUT TO 0V
high 4
low 5
goto main
green:
sertxd ("green",13,10)
pwmout 2,99,125 ;SET THE OUTPUT TO 1.5V
low 4
high 5
goto main
blue:
sertxd ("blue",13,10)
pwmout 2,99,250 ;SET THE OUTPUT TO 3V
high 4,5
goto main