Newbie desperately needs help to read 3 inputs to meet 7 cases
I am using 1 BS2P as a main processor to ping room with an SRF10. If it meets 1 of 7 certain conditions it outputs it via 3 outputs (pins 5 - 6 - 7 ) to a second BS2P that controls an LED matrix I need code that would read the high / low states of the LED micro on pins 5 - 6 - 7 to then instruct the program to goto mode1, mode2, mode3, mode4, mode5, mode6, and mode7. If you can can help me with some detailed code that uses cases or branches or whatever It would make my week/month.
Thanks
Daniel
Thanks
Daniel
Comments
Led_output· VAR Nib
Led_output=OUTB>>1 & 7·· 'shift the 4 bits·right 1 place and filter the lower 3 bits (P5 6 & 7)
ON Led_output GOSUB mode_0,mode_1,mode_2.........etc
Jeff T.
Post Edited (Unsoundcode) : 7/29/2008 5:54:50 PM GMT
Thanks for the help but if you could just give me a little more of the layout I think I could pick it up more quickly.
I need to read P0 P1 and P2 of the MAINIO to generate a value that can then either put into a series of CASE conditions or IF THEN ELSE statements that will in turn jump the program to:
LED_MODE1
LED_MODE2
LED_MODE3
LED_MODE4
LED_MODE5
LED_MODE6
LED_MODE7
There must also be something in these GOTOs or GOSUBs that will scan P0,P1, and P2 every so often to see if the value has changed so that the program can jump to the correct LED_MODE
Thanks for your help it is really helping me to get my art piece done and to learn more
Daniel
If you just want to react to changes, you'll need a variable (declared as a nibble) to hold the previous value like this subroutine:
Each LED_MODEx routine would end with a RETURN.
Thanks for the help!
I tried stiching together your suggestions but it does not seem to work for me.
I think I may have left out something that might be a no-brainer to you guys but to a Newbie like me it might get past me.·I have attached·my working code with·a solution that·I can understand but I am sure that your solutions are far more elegant, faster, and shorter code.· I appreciate your help I am racing to a deadline and my friend that was assisting me with writing the code is not available, so I am on my own to learn a lot in very little time.
The code has very clear notes at the heading·on where I am stuck.
Thanks again
Daniel
Post Edited (Nauketec) : 8/25/2008 5:29:51 AM GMT
·'P0 OUT TO LED BS2P40 TO SEND WHICH SELECTED MODULE 0 - 7 TO RUN
·'P1 OUT TO LED BS2P40 TO SEND WHICH SELECTED MODULE 0 - 7 TO RUN
·'P2 OUT TO LED BS2P40 TO SEND WHICH SELECTED MODULE 0 - 7 TO RUN
·'P3 NOT USED
·'P10 NOT USED
·'P11 NOT USED
·'P12 DIP SWITCH #1 (BIN·1 COLUMN)PULLED HIGH WITH 4.7K RESISTOR
·'P13 DIP SWITCH #2 (BIN·2 COLUMN)PULLED HIGH WITH 4.7K RESISTOR
·'P14 DIP SWITCH #3 (BIN·4 COLUMN)PULLED HIGH WITH 4.7K RESISTOR
·'P15 DIP SWITCH #4 (BIN·8 COLUMN)PULLED HIGH WITH 4.7K RESISTOR
Jeff T.
Can't change pins - the board was made ( I now know that it should have been designed to make the code· easier but that is what learning is all about.· My problem is I have a deadline and must do the best I can to get the job done.· Thanks for any help you can offer.· I have been reading as much as I can buiut it is a lot to learn in a short time.
What I am trying to do is have the first of two BS2P40 micros· scan the four dips (only once at power-up)on P10 P11 P12 P13 and from them set which of 15 programs to run.·I do this·in the· "Initialize:" section.
The "Main:" section then·uses a Davantech·sonar SRF10 SCL on P4 and SDA on P5 to detect:
This information is used for a series of IF THEN GOTOs or CASES to set
P1 P2 P3 to values that send the information to a second BS240
The information on the second (led control) micro is read on P0 P1 P2 on that chip
where it runs 7 different LED pattern modes (mode0, mode1, mode2 .... mode7)
It runs part of the led pattern then checks P0 P1 P2 for changes and returns to the same mode or updates to a new one.
That is it but for a newbie its enough!· Thanks again for all your help!· My programmer is unavailable. I tried to hire a consultant but none were available on short notice.· So now I am staying up till 3:00am and greatly appreciating any help I can get here.
Daniel
Post Edited (Nauketec) : 8/25/2008 5:30:41 AM GMT
One solution would be to extract the 4 bits from INH and reverse them to give a number between 0 and 15, then use the ON..GOSUB instruction to jump to the "mode" routine. That would do away with all the IF..THENS you had in version 1.
eg.
Dip_Switch VAR Byte
Dip_Switch=(INH REV· 8 >>2) & 15·· 'reverse the high byte of the INS register , shift the result right 2 places then AND that result with 15 to derive a number between 0 and 15
ON Dip_Switch GOSUB mode_0,mode_1,mode_2...........etc
Jeff T.
The confusion is do you identify an input / output by pin number or by port number I was using P0 to P15 not pin numbers.
for my applications on the first micro I need to read DIP switches on pins 15,16,17,18 (also known as ports P10,P11,P12,P13
and set up 1-15 cases or if then gotos I also then need to send 1 to 7 conditions out pins 6,7,8 (also known as P1,P2,P3)
on the second micro I need to read the data from the first by reading pins 5,6,7 (also know as P0,P1,P2)
If you could help me to setup a way for those two apps to read them in bin or dec it would be a great help
You can look at the code I included to see the long way I did it.
Thanks
Daniel
Thanks for the help
the on Dip_switch Gosub mode1..... is what I am not so clear
Will your code generate a number that I read and then for each dip switch position write on dipswitch = 0 gosub mode 0?
Daniel
Jeff T.
·
Thanks a lot !· Your help has not only resolved the issue but has given me a great learning opportunity as well.
I have moved my next task over to the basic stamp forum· please meet me there with your continued good will
Thanks again
Daniel
end thread