Could someone tell me why????
CRST1
Posts: 103
I have this simple code that uses 1 input and 1variable bit and I can't fathom why it is not working right.
It's really simple, when the input goes high it runs a sub and sets bit to high so it does not run sub again while it stays on. When it goes low it runs a sub and sets bit low so it does not run sub again while it is low. It work when it goes high but when it goes low it does not run the sub. I used "bit = 1". I found if I use "bit > 0" it works. If it is a bit variable then how can bit = 1 not work but bit = 0 does work and bit > 0 also work.
I am really confused. It's on a basic stamp2sx.
I use the prop and the prop2 and never saw anything like this.
I apologize for no formatting code but can't figure out how to insert it now.
' {$STAMP BS2sx} ' {$PBASIC 2.5} DIRS = %1111100000011111 OUTS = %0000000000000000 delay VAR Byte brake_on VAR Bit delay = 300 Main: 'Brake on with both signals off IF IN7 = 1 THEN PAUSE 25 IF IN7 = 1 & brake_on = 0 THEN GOSUB BrakeOn ENDIF ENDIF 'Brake off with both signals off IF IN7 = 0 THEN PAUSE 25 IF IN7 = 0 & brake_on = 1 THEN GOSUB BrakeOff ENDIF ENDIF GOTO Main BrakeOn: IF brake_on = 0 THEN brake_on = 1 OUTS = %1000000000000001 PAUSE delay OUTS = %1100000000000011 PAUSE delay OUTS = %1110000000000111 PAUSE delay OUTS = %1111000000001111 PAUSE delay OUTS = %1111100000011111 PAUSE delay ENDIF RETURN BrakeOff: IF brake_on = 1 THEN brake_on = 0 OUTS = %0000000000000000 ENDIF RETURN
Comments
It's been a while since I've used a Basic Stamp but shouldn't the code:
IF IN7 = 1 & brake_on = 0 THEN
Be written ?:
IF IN7 = 1 AND brake_on = 0 THEN
I think the "&" symbol is a bitwise and instead of a logical and.
Thank you. It's been a long time since basic stamp for me also. I have a few laying around and figured I would use one for the lights in a car project.
You're right I forgot that.
By the way how do you insert code in this new forum format? It's been a while.
Thanks
You use this character three times in a row. `
It's the character under the tilde on my keyboard. You start the code block with three of these characters and end the code block the same way.
If you quote the reply with the code block, you should be able to see these characters.
I've added some debug so you can see whats going on, sequence, load, take pin 7 high, then pin 7 low. Bs2