Complex expression error
MrRedHair
Posts: 9
I was programming my boe-bot to be controlled by a normal IR remote control, one that normal goes to a a tv, this morning. After I finished typing the IF...THEN statements, I go to run the program and I get an error message that says "Expression is too complex". I've never seen this error before and would like some help on how to still upload my program to do what it should.
PS: It isn't set up to run the motors yet. Only post a sentence via DEBUG statements.
PS: It isn't set up to run the motors yet. Only post a sentence via DEBUG statements.
' {$STAMP BS2} ' {$PBASIC 2.5} time VAR Word(5) DEBUG "Program Initialization.", CR FREQOUT 4, 800, 3000 DO DO RCTIME 9, 1, time(0) LOOP UNTIL time(0)> 1000 PULSIN 9, 0, time(0) ' Measure/store data pulses. PULSIN 9, 0, time(1) PULSIN 9, 0, time(2) PULSIN 9, 0, time(3) PULSIN 9, 0, time(4) IF (time(4) < 400) THEN IF time(3) < 400) THEN IF (time(2) < 400) THEN IF (time(1) < 400) THEN IF (time(0) < 400) THEN DEBUG "The 1 button is being pressed.", CR PAUSE 750 ELSEIF (time(0) > 600) THEN DEBUG "The 2 button is being pressed.", CR PAUSE 750 ENDIF ELSEIF (time(1) > 600) THEN IF (time(0) < 400) THEN DEBUG "The 3 button is being pressed.", CR PAUSE 750 ELSEIF (time(0) > 600) THEN DEBUG "The 4 button is being pressed.", CR PAUSE 750 ENDIF ENDIF ELSEIF (time(2) > 600) THEN IF (time(1) < 400) THEN IF (time(0) < 400) THEN DEBUG "The 5 button is being pressed.", CR PAUSE 750 ELSEIF (time(0) > 600) THEN DEBUG "The 6 button is being pressed.", CR PAUSE 750 ENDIF ELSEIF (time(1) > 600) THEN IF (time(0) < 400) THEN DEBUG "The 7 button is being pressed.", CR PAUSE 750 ELSEIF (time(0) > 600) THEN DEBUG "The 8 button is being pressed.", CR PAUSE 750 ENDIF ENDIF ENDIF ELSEIF (time(3) > 600) THEN IF (time(2) < 400) THEN IF (time(1) < 400) THEN IF (time(0) < 400) THEN DEBUG "The 9 button is being pressed.", CR PAUSE 750 ELSEIF (time(0) > 600) THEN DEBUG "The 0 button is being pressed.", CR PAUSE 750 ENDIF ELSEIF (time(1) > 600) THEN IF (time(0) > 600) THEN DEBUG "The ENTER button is being pressed.", CR PAUSE 750 ENDIF ENDIF ENDIF ENDIF ELSEIF (time(4) > 600) THEN IF (time(2) < 400) THEN IF (time(1) < 400) THEN IF (time(0) < 400) THEN DEBUG "The Ch+ button is being pressed.", CR PAUSE 750 ELSEIF (time(0) > 600) THEN DEBUG "The Ch- button is being pressed.", CR PAUSE 750 ENDIF ELSEIF (time(1) > 600) THEN IF (time(0) < 400) THEN DEBUG "The Vol+ button is being pressed.", CR PAUSE 750 ELSEIF (time(0) > 600) THEN DEBUG "The Vol- button is being pressed.", CR PAUSE 750 ENDIF ENDIF ENDIF ENDIF LOOP
bs2
3K
Comments
It is an interesting puzzle, to restructure, given your time-weighted inputs. What happens if a button is pressed in the no-mans-land between 400 and 600? I would suggest forming a single integer with binary digits corresponding to the time values being on one side or the other of 500ms, and then work with that integer.
The time() values do not matter in the end.
Then the algorithm ends up with keys=%10001. If time(1) is also ~650, then the algorithm ends up with keys=%10011. The PBASIC syntax allows setting individual bits in a variable.
keys.bit0=1.
You end up with a numerical code from 0 to 31 for all the possiblities,
DEBUG CR, "The key value is ", DEC keys
So %00001 prints 1. Or %10011 prints 19. and so on. There may need to be an additional mapping step between the numerical value of keys and what gets printed. E.g. The keys=17 may map into a string of "channel" and a number, but from the keys value you can take advantage of LOOKUP and LOOKDOWN commands.