Say It generated code faulty?
I've just generated the portion of code underneath with the Say It module:
I don't know why but only the first group of i.e CASE G0_BOE is executed. The code ignores all other cases. Am I doing sth wrong?
VR_Action:
DEBUG "got ", DEC VRCOMMAND
SELECT VRGROUP
CASE GROUP_0
SELECT VRCOMMAND
CASE G0_BOE
PAUSE 0 '-- write your code here
ENDSELECT
CASE GROUP_1
SELECT VRCOMMAND
CASE G1_FORWARD
PAUSE 0 '-- write your code here
CASE G1_BACKWARD
PAUSE 0 '-- write your code here
CASE G1_RIGHT
PAUSE 0 '-- write your code here
CASE G1_LEFT
PAUSE 0 '-- write your code here
CASE G1_STOP
PAUSE 0 '-- write your code here
ENDSELECT
ENDSELECT
RETURN
I don't know why but only the first group of i.e CASE G0_BOE is executed. The code ignores all other cases. Am I doing sth wrong?

Comments
Sorry I'm away from my pc
VR_Action: DEBUG "got ", DEC VRCOMMAND SELECT VRGROUP CASE GROUP_0 SELECT VRCOMMAND CASE G0_BOE PAUSE 0 '-- write your code here ENDSELECT CASE GROUP_1 SELECT VRCOMMAND CASE G1_FORWARD PAUSE 0 '-- write your code here CASE G1_BACKWARD PAUSE 0 '-- write your code here CASE G1_RIGHT PAUSE 0 '-- write your code here CASE G1_LEFT PAUSE 0 '-- write your code here CASE G1_STOP PAUSE 0 '-- write your code here ENDSELECT ENDSELECT RETURNSee how much more readable your code is?
Anyway, your 'problem' is that you have a set of nested CASE statements. The first, working with the VRGROUP variable splits the program in TWO blocks, and only one of those can be executed.
(GROUP_0 or GROUP_1 )
Drawing a flow diagram can also help.
vars... Lots of other code... IF SpokenWord = "BOE" CASE First_case Second_case Third_case ... Last_case ELSE - Not BOE... ENDIFSorry that I can't write more clearly, but I think it's something like this you want...
(I haven't programmed a BS2 in a couple of years... )
It always helps to write your program in 'pseudocode' first, then transfer it to 'proper' code afterwards.
Another thing I like to do is to print the code, then use a couple of underliners, draw large '[', starting at the beginning of the IF/CASE/DO/Whatever 'Flow control' command, towards the margin, down, and out to the ENDIF/ENDSELECT and so on. With another line out to the start of every ELSE/Select, you can see more clearly what is and isnt executed when a certain condition exists or not.
http://forums.parallax.com/showthread.php?132551-generating-functional-code-Sayit-Module-and-Parallax-Digital-I-O-Board
see post #six
VR_Action: DEBUG "got ", DEC VRCOMMAND SELECT VRGROUP CASE GROUP_0 SELECT VRCOMMAND CASE G0_BOE PAUSE 0 GOSUB LED_ON CASE G1_FORWARD PAUSE 0 GOSUB FORWARD CASE G1_BACKWARD PAUSE 0 GOSUB BACKWARD CASE G1_SPIN_RIGHT PAUSE 0 GOSUB SPIN_RIGHT CASE G1_SPIN_LEFT PAUSE 0 GOSUB SPIN_LEFT CASE G1_TURN_RIGHT PAUSE 0 GOSUB TURN_RIGHT CASE G1_TURN_LEFT PAUSE 0 GOSUB TURN_LEFT ENDSELECT CASE GROUP_1 PAUSE 0 ENDSELECT RETURN LED_ON: FOR counter=1 TO 10 HIGH 10 PAUSE 500 LOW 10 PAUSE 500 NEXT FORWARD: 'DEBUG CR, "Robot Forward" FOR counter = 1 TO 50 PULSOUT LServo, 1000 PULSOUT RServo, 500 PAUSE 20 NEXT RETURN BACKWARD: 'DEBUG CR, "Robot Backward" FOR counter = 1 TO 50 PULSOUT LServo, 500 PULSOUT RServo, 1000 PAUSE 20 NEXT RETURN SPIN_RIGHT: 'DEBUG CR, "Robot Spin right" FOR counter = 1 TO 50 PULSOUT LServo, 1000 PULSOUT RServo, 1000 PAUSE 20 NEXT RETURN SPIN_LEFT: 'DEBUG CR, "Robot Spin left" FOR counter = 1 TO 50 PULSOUT LServo, 500 PULSOUT RServo, 500 PAUSE 20 NEXT RETURN TURN_LEFT: 'DEBUG CR, "Robot Turn Left" FOR counter = 1 TO 85 PULSOUT LServo, 750 PULSOUT RServo, 500 PAUSE 20 NEXT RETURN TURN_RIGHT: 'DEBUG CR, "Robot Turn Right" FOR counter = 1 TO 85 PULSOUT LServo, 1000 PULSOUT RServo, 750 PAUSE 20 NEXT RETURNThis is the portion of the code, I am talking about. Unfortunately only the command BOE turns the LED on (is executed). All the rest (FORWARD, BACKWARD, TURN_LEFT etc) are ignored...
Thanks for your help anyway!
Sounds like you need to use the BOE word to change the GROUP from 0 to 1. This is what I did with my Speaking, Voice-Recognizing Home Automation System. See Voice Recognition code from my project below. Saying "Computer" changes the code vrom VRGROUP10 to VRGROUP1 - meaning it stops listening for Computer once it hears it and starts listening for teh commands to actually do stuff. Here's the code:
VR_Action: DEBUG DEC VRCOMMAND SELECT VRGROUP CASE GROUP_0 SELECT VRCOMMAND CASE G0_COMPUTER PAUSE 0 HIGH VRLED GOSUB Listen_Tone ' << This is just a place where I make it chirp at me to let me know it heard my wake-up command. VRGROUP = 1 ' <<<<<<<<<< Here's the place you change to VRGROUP 1 so it starts listening for commands. ENDSELECT CASE GROUP_1 SELECT VRCOMMAND CASE G1_OUTSIDE_WATER_ON PAUSE 0 state = 1 s1 = state cmd = 2 GOSUB Bank_Build CASE G1_OUTSIDE_WATER_OFF PAUSE 0 state = 0 s1 = state cmd = 2 GOSUB Bank_Build CASE G1_OUT_PEAK_LIGHT_ON PAUSE 0 state = 1 s2 = state cmd = 3 GOSUB Bank_Build CASE G1_OUT_PEAK_LIGHT_OFF PAUSE 0 state = 0 s2 = state cmd = 3 GOSUB Bank_Build CASE G1_SECURITY_LIGHT_ON PAUSE 0 state = 1 s3 = state cmd = 4 GOSUB Bank_Build CASE G1_SECURITY_LIGHT_OFF PAUSE 0 state = 0 s3 = state cmd = 4 GOSUB Bank_Build CASE G1_TABLE_LIGHT_ON PAUSE 0 state = 1 s4 = state cmd = 5 GOSUB Bank_Build CASE G1_TABLE_LIGHT_OFF PAUSE 0 state = 0 s4 = state cmd = 6 GOSUB Bank_Build CASE G1_ENT_CENTER_ON PAUSE 0 state = 1 s5 = state cmd = 6 GOSUB Bank_Build CASE G1_ENT_CENTER_OFF PAUSE 0 state = 0 s5 = state cmd = 6 GOSUB Bank_Build CASE G1_LANDSCP_LIGHTING_ON PAUSE 0 state = 1 s6 = state cmd = 7 GOSUB Bank_Build CASE G1_LANDSCP_LIGHTING_OFF PAUSE 0 state = 0 s6 = state cmd = 7 GOSUB Bank_Build CASE G1_WHAT_TIME_IS_IT PAUSE 0 GOSUB Get_Time GOSUB Show_Time PUT Speak, 102 RUN SG CASE G1_TEMPERATURE PAUSE 0 GOSUB Get_Temp GOSUB Show_Temp PUT Speak, 103 RUN SG CASE G1_WHAT_DAY_IS_TODAY PAUSE 0 GOSUB Get_Time GOSUB Show_Time PUT Speak, 101 RUN SG ENDSELECT CASE GROUP_16 SELECT VRCOMMAND CASE G16_XANATOS_ALPHA_ONE PAUSE 0 cmd = 40 RUN SG ENDSELECT ENDSELECT RETURNLet me know if that helps. This is just a piece I have as a subroutine in my full program. Search for that Speaking, Voice-Recognizing Home Automation System thread to see FAR more details...
Here's your code with the requisite line included:
VR_Action: DEBUG "got ", DEC VRCOMMAND SELECT VRGROUP CASE GROUP_0 SELECT VRCOMMAND CASE G0_BOE PAUSE 0 '-- write your code here VRGROUP = 1 ' <<<<<<<<<<<<<<<<<<<<<<<<<< Here's your group switch... ENDSELECT CASE GROUP_1 SELECT VRCOMMAND CASE G1_FORWARD PAUSE 0 '-- write your code here CASE G1_BACKWARD PAUSE 0 '-- write your code here CASE G1_RIGHT PAUSE 0 '-- write your code here CASE G1_LEFT PAUSE 0 '-- write your code here CASE G1_STOP PAUSE 0 '-- write your code here ENDSELECT ENDSELECT RETURNGood luck,
Dave
I will make the change from GROUP 0 to GROUP1 (i.e VRGROUP=1) and I will let you know...Thanks again!