Stop Flashing you stupid led!!!!!!!!!

TEZARM

Senior Member
Hey guys, can someone help out with this problem please. PICAXE 18A. I am using a transistor (npn) on the output of picaxe to trigger an input of same picaxe. When this input is grounded the picaxe will flash a light on a different output twice and than stop. The problem is IT WON'T STOP FLASHING!!!!!! Stop!!!
I know why, it's because the transistor keeps the pin grounded all the time while triggered and picaxe keeps looping. So how do i stop this from happening? I just need 1 output to trigger the transistor which triggers 1 input which tells another output to turn an led on and off twice and then stop BUT the transistor still needs to keep input grounded until I tell it to turn off. Sounds so simple, but it's not! I hate the program code side of picaxes and I think it hates me aswell so we are not the best of friends. So someone on here care to help frusrated TEZARM? Pretty please?
 

Jeremy Leach

Senior Member
It's a bit difficult to grasp the situation (!) but perhaps your code that senses the input state of the pin needs to detect a <i>change </i> in level in order to activate, rather than a set level ? This way it won't keep retriggering?
 

BeanieBots

Moderator
I agree with Jeremy on both counts. Not sure exactly what you're trying to do but sounds like the code should detect pin state change or at least have a way to exit the loop once done.
I know it's difficult in text but maybe have another go at explaining the desired sequence of events.
 

SD2100

New Member
I had a guess what you wanted to do, this will flash an led twice when an input <i>TransistorTrigger </i> goes high, the flashing will then stop even if the input remains high. The <i>TransistorTrigger </i> input has to go low to reset <i>Latch </i> before the led is allowed to flash again.
The <i>InputFromTransistor </i> input has to be pulled high by a 10k resistor etc and is pulled low when the transistor is turned on.
<code><pre><font size=2 face='Courier'>
#picaxe 18A

symbol TransistorTrigger = pin0 'High on this input turns transistor ON
symbol InputFromTransistor = pin1 'This input pulled up with 10k resistor, tranny will pull it low
symbol Transistor = 0 'Turns Transistor ON/OFF
symbol led = 1 'The flasher
symbol latch=b1 'Only allows one flash cycle until state of trigger changes

do
select case TransistorTrigger 'Triggered by some external thing ???
case 0 'Trigger is low
latch =0 'reset when trigger has changed
case 1 'Trigger is high so do flash only if trigger changed since last flash
if latch=0 then 'Only allow flash when = to 0
high Transistor 'Turn ON tranny which causes input to go low
pause 10 'maybe needed to give tranny time to pull input low
if InputFromTransistor=0 then 'Goes low then tranny is ON
low Transistor 'Turn Tranny OFF
for b0=0 to 1 'Flash twice
high led
pause 200
low led
pause 200
next
latch=1 'Done flash so disable until next trigger
end if
end if
end select
loop </font></pre></code>


Edited by - Phil75 on 06/11/2006 15:39:08
 

TEZARM

Senior Member
And I thought I had explained myself well this time? Actually you are ALL correct in what you are thinking. Thanks for that Phil, but I can't get that to work and am to stupid to figure out why it won't work. It will be something I am doing though and I appreciate your help in trying. Program Editor says error in 'do' line????
Your guess is right though in what I want to do but I thought it might be simpler and need it to be built into my code so I am now going to post my entire code so as to make it easier for everyone. This code is for an ongoing car alarm project. There is a million mistakes in it as I absolutely suck at programming but it works for now so I guess one step at a time. OK so here goes, and I will explain this problem I am having again below the code. Also Interested in any things I could do to improve code ofcourse but please remember you are trying to explain this to TEZARM who has a very small brain so explain as you would to a 5 year old. Sorry about all this code by the way. Everything with ????? next to it and in CAPITALS is the problem I am talking about. Here goes...

'TEZARM'S CAR ALARM CODE

'LED = o/p7 'DOORS / FULL TRIGGER = i/p2
'UNLOCK = o/p6 'PRECHIRP = i/p6
'LOCK = o/p5 'ALARM ON/OFF RECOGNITION PIN INPUT = i/p1 ?????
'(-)WHEN ARMED = o/p1 'DISARM = i/p0
'PARKLIGHTS = o/p3 'ARM = i/p7
'EXT SIREN = o/p4 'ALARM ON/OFF RECOGNITION PIN OUTPUT = O/P0 ?????
'IMMOBILISER = o/p2 (N/O Relay)

start:


if pin1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if pin1=1 and pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if pin1=0 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if pin1=0 and pin0=1 and pin7=1 and pin2=1 and pin6=0 then prechirp
if pin1=0 and pin0=1 and pin7=1 and pin2=0 and pin6=1 then fulltrigger



alarmon: 'Turn Alarm System On
low 2 'Turn OFF Immobiliser
pause 500 'Wait 500 milli seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 1000 'Wait 1 Second
high 5 'Pull Central Lock Motor
pause 500 'Wait 500 milli Seconds
low 5 'Release Pulse To Central Lock Motor
pause 2000 'Wait 2 Seconds
high 1 'Turn On (-) When Armed Wire
high 7 'Turn On Status Led
HIGH 0 'TURN ON ALARM ON/OFF RECOGNITION PIN TRANSISTOR ?????
goto start

alarmoff: 'Turn Alarm System Off
low 1 'Turn Off (-) When Armed Wire
pause 500 'Wait 500 milli seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Second
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 200 'Wait 200 Milli Seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Second
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 500 'Wait Half A Second
high 6 'Pull Central UNLock Motor
pause 500 'Wait 500 milli Seconds
low 6 'Release Pulse To Central UNLock Motor
pause 2000 'Wait 2 Seconds
low 7 'Turn Off Status Led
pause 500 'Wait 500 milli Seconds
high 2 'Turn On Immobiliser
pause 500 'Wait 500 milli Seconds
high 3 'Turn On Parklights
high 4 'Turn On External Siren
pause 100 'Wait 100 milli seconds
low 3 'Turn Off Parklights
low 4 'Turn Off External Siren
pause 100 'Wait 100 milli seconds
high 3 'Turn On Parklights
high 4 'Turn On External Siren
pause 100 'Wait 100 milli seconds
low 3 'Turn Off Parklights
low 4 'Turn Off External Siren
pause 100 'Wait 100 milli seconds
high 3 'Turn On Parklights
high 4 'Turn On External Siren
pause 100 'Wait 100 milli seconds
low 3 'Turn Off Parklights
low 4 'Turn Off External Siren
pause 500 'Wait Half A Second
high 2 'Turn On Immobiliser
LOW 0 'TURN OFF ALARM ON/OFF RECOGNITION PIN TRANSISTOR ?????
goto start



prechirp: 'Prechirp Wire For Sensors
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 200 'Wait 200 Milli Seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 200 'Wait 200 Milli Seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 200 'Wait 200 mlli seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 milli seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 200 'Wait 200 milli seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 milli seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
goto start

fulltrigger:
pause 500 'Wait Half a Second
high 4 'Turn On External Siren
pause 3000 'Scream Siren for 3 Seconds
low 4 'Turn Off Siren
goto start

So, Ouput 0 triggers a transistor which turns Input 1 on or off (Forget the led I explained first to you as that was just an example)
By doing this with a transistor on an Input of Picaxe allows me to get the alarm to ONLY do certain features when it see Input 1 is on or off. e.g. Opening the doors WILL NOT make alarm scream when INPUT ONE IS OFF (HIGH). This is because the alarm is OFF as Output 0 has NOT turned on the transistor at this stage. So by NOT turning transistor ON I can get alarm to ignore Inputs

1. Door Trigger
2. Prechirp
3. Immobiliser
This is very imporatant to me as if I don't have this input with transistor on it than the alarm would scream everytime you opened a door irrespective of whether the alarm is on or off. So what I am trying to say is this transistor tells Input 1 IF THE ALARM IS ON or OFF. I hope you can all now understand what I am trying to do. So if you would be able to try again I would really appreciate it as I cannot figure this stuff out myself. Thanks guys. Might be easier to copy / paste this out to notepad to understand it as posting code on to the forum makes it look extremely confusing as it scrambles it all over the place.










 

BeanieBots

Moderator
TEZARM, to run the code written by Phil75 you must be using the latest beta version of the editor which supports &quot;do&quot; loops.

Also, look up for/next structure in the manual. It will help simplify your code a great deal and use less code space.

eg to switch on/off outputs 2 &amp; 3 10 times:-

for b0=1 to 10
high 2
high 3
pause 200
low 2
low 3
pause 200
next b0
 

TEZARM

Senior Member
Thanks for that Beaniebots. The problem is though that my brain cannot understand the programming side of things. I am really really really stupid at the programming. It's like trying to learn another language and not succeeding. For example, if I use Phil's code, how on earth do I write that into my code. I have no idea what Phil's code is actually doing, to me it's very very very confusing. I don't know how to start off a program except for the way i have done so above but is that the only way i can do it for what i am trying to do here? I am happy to just leave it as it is at this stage cos I can understand it but I don't understand how to get this transistor input to work and thats the important part at the moment. Oh and yes, that will be why Phils code is not working cos I have an older version of the editor at the moment. I can't understand the old version so theres no point in me upgrading yet I guess.

Can someone please tell me how to put this transistor part into my program????
 

BeanieBots

Moderator
May I suggest using flow diagrams as a way of learning. Perhaps a more visual method might work for you. It is very hard to explain such detail without direct interaction.
Also, you will probably have a better understanding of the new edititor as it can produce much more readable code with the better structures. The older version often required little &quot;tricks&quot; such as logic reversal to get around the limited command set.
 

TEZARM

Senior Member
Beaniebots. Can I use the READ command to monitor the input? How?
Nope, I find those Flow Diagrams even harder than writing the code myself.
You said find some way of exiting the loop? How do I do that?
 

Dippy

Moderator
Can you post your circuit schematic.
It may be that someone can suggest something clearer for you.
And they may even be able to suggest a way of cutting out the transistor... you never know.
Remember, you are very 'close' to this project and everyone else has to try and interpret it into their own 'picture'.
 

Fowkc

Senior Member
There isn't (unfortunately) a facility to upload pictures to the forum. Either upload it to imageshack or photobuckt or some external website and provide a link, or you can draw the circuit using ASCII art, i.e.
<code><pre><font size=2 face='Courier'>
___
|
---
\ / Diode or LED
-----
|
---

</font></pre></code>

I'm not very good at it!
 

TEZARM

Senior Member
Picasso, it's you again!!!
Thanks. I will do that mate. Give a few minutes guys and i'll sort something out.
 

TEZARM

Senior Member
Geez, what a bloody mission that was. I lost it after uploading so had to upload twice. I am a clumsy dork at times.

http://tinypic.com/view/?pic=4gz1en6

Thanks for that tip Picasso. Ok now hurry up and get your thinking caps on guys as this is driving me nuts. Can someone please let me know if this diagram makes sense ok. Thanks Guys
 

TEZARM

Senior Member
I took Beaniebots advice and have simplified my code aswell so here it is which might make it easier for you to understand. It has only taken me about 6 bloody hours and to my amazement it actually works!! Huh? How did that happen?
TEZARM your getting better at this. I think I may have even made Beaniebots proud.

'TEZARM

'LED = o/p7 'DOORS / FULL TRIGGER = i/p2
'UNLOCK = o/p6 'PRECHIRP = i/p6
'LOCK = o/p5 'ALARM ON/OFF RECOGNITION PIN INPUT = i/p1 ?????
'(-)WHEN ARMED = o/p1 'DISARM = i/p0
'PARKLIGHTS = o/p3 'ARM = i/p7
'EXT SIREN = o/p4 'ALARM ON/OFF RECOGNITION PIN OUTPUT = O/P0 ?????
'IMMOBILISER = o/p2 (N/O Relay)

start:


if pin1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if pin1=1 and pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if pin1=1 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if pin1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=0 then prechirp
if pin1=1 and pin0=1 and pin7=1 and pin2=0 and pin6=1 then fulltrigger



alarmon: 'Turn Alarm System On
low 2 'Turn OFF Immobiliser
pause 200 'Wait 200 milli seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 100 'Wait 100 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 500 'Wait 500 Milli Seconds
high 5 'Pull Central Lock Motor
pause 500 'Wait 500 Milli Seconds
low 5 'Release Pulse To Central Lock Motor
pause 2000 'Wait 2 Seconds
high 1 'Turn On (-) When Armed Wire
high 7 'Turn On Status Led
'HIGH 0 'TURN ON ALARM ON/OFF RECOGNITION PIN TRANSISTOR ?????
goto start

alarmoff: 'Turn Alarm System Off
low 1 'Turn Off (-) When Armed Wire
pause 200 'Wait 200 milli seconds
for b0=1 to 2 'Flash / Chirp 2 Times
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 100 'Wait 100 Milli Second
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 100 'Wait 100 Milli Seconds
next b0 'Ending To 2 Times Flash / Chirp
pause 500 'Wait 500 milli Second
high 6 'Pull Central UNLock Motor
pause 500 'Wait 500 milli Seconds
low 6 'Release Pulse To Central UNLock Motor
pause 1000 'Wait 1 Second
low 7 'Turn Off Status Led
pause 500 'Wait 500 milli Seconds
high 2 'Turn On Immobiliser
pause 200 'Wait 200 milli Seconds
for b1=1 to 3 'Flash / Chirp 3 Times for Immobiliser
high 3 'Turn On Parklights
high 4 'Turn On External Siren
pause 100 'Wait 100 milli seconds
low 3 'Turn Off Parklights
low 4 'Turn Off External Siren
pause 100 'Wait 100 Milli Seconds
next b1 'Ending To 3 Times Flash / Chirp
high 2 'Turn On Immobiliser
'LOW 0 'TURN OFF ALARM ON/OFF RECOGNITION PIN TRANSISTOR ?????
goto start


prechirp: 'Prechirp Wire For Sensors

for b2=1 to 5 'Flash / Chirp 5 Times for Prechirp
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 200 'Wait 200 Milli Seconds
next b2 'Ending To 5 Times Flash / Chirp
goto start


fulltrigger:

high 4 'Turn On External Siren
pause 3000 'Scream Siren for 3 Seconds
low 4 'Turn Off Siren
goto start













 

TEZARM

Senior Member
Can you see any mistakes in this BeanieBots. If so can you please tell me so I can fix them up. I was purely going by your example you gave me so was a little confused when putting it together in my millions of lines code.
 

BeanieBots

Moderator
I can't see any mistakes because quite frankly I have no idea what it should be doing!
Anyway, you said it works, so leave it alone!

Of course I'm proud of you. You keep on going despite the frustrations and that has to be admired. Many would simply give up at the first hurdle.

Don't totally dismiss flow charts. I don't mean use the built in flow chart. I mean draw it out on paper so that you get a &quot;picture&quot; of what is going on.
I'll leave it to others to wade through your code. I'm more electronics than software and only just get by myself.
 

Bloody-orc

Senior Member
is it possible to see your full schematic of that button placement and LED circuit with all the part numbers etc.
 

BeanieBots

Moderator
I've just had a proper look at your diagram.
Output 0 drives a transistor which in turn drives input 1. There is nothing else connected to input 1 except the pullup. The net result is that input 1 is nothing more than the inverse of output 0.
Is this correct?
If yes, you can loose the transistor, forget output 0 and do that bit in code!

Edited by - beaniebots on 08/11/2006 18:11:13
 

Bloody-orc

Senior Member
sry didn't see the schematic link before.
anyway yes what are you trying to achieve with this out0-&gt;npn-&gt;inp line? Want to make software reset of some kind?
 

TEZARM

Senior Member
Hi Bloody-orc. No mate, thats not what I am trying to do at all. It's not restting the picaxe, it's purely giving the software 2 stages where while the transistor is on only some inputs will be acceptable to triggering and when off pretty much all inputs are acceptable to triggering. It stops certain unwanted features of alarm working while alarm is turned off. If you read my earlier posts I have explained in there aswell but everyone seems to be confused so i don't know if I have explained to well. Thanks Mate.


&quot;Is this correct?

Yes BeanieBots that is exactly correct.

&quot;If yes, you can loose the transistor, forget output 0 and do that bit in code!&quot;

Not understand what you mean? Can you give me an example. Just let me explain once more first incase you are thinking down the wrong lines as I don't know how what you said will work. This is an example for you all. I will use the door switches of car as an example.

e.g.

When you arm alarm it turns ON THE TRANSISTOR PERMANENETLY.
When you disarm alarm it turns OFF TRANSISTOR PERMANENTLY.
If I open a door when alarm is armed, first thing it does is checks whether the TRANSISTOR is ON or OFF.
If the transistor is ON then it screams the siren.
If the transistor is OFF then it DOES NOT scream the siren. The reason it does not is because if the alarm is off (TRANSISTOR OFF ASWELL) than that would mean that you could open the doors anytime AND the alarm would scream ALL THE TIME. So it never would know when the time to scream siren should be so it needs the Transistor to tell the Doors IF THE ALARM IS ON or OFF so it knows what to do. And it does this for a couple of other features aswell but I guess you get the picture form this. You Guys Dig?
 

Fowkc

Senior Member
I think I understand, and they're right, you don't actually need the transistor. If your transistor output (output0) is turned ON, then your input1 is LOW and vice-versa.

So every time you have a HIGH 0, you always know that input1 = 0. So, instead of having a physical transistor, we can have a byte variable called transistor:
<code><pre><font size=2 face='Courier'>
SYMBOL b0 = transistor
</font></pre></code>

Then in your code, when you have <code><pre><font size=2 face='Courier'>HIGH 0 </font></pre></code> , replace it with <code><pre><font size=2 face='Courier'>transistor = 1 </font></pre></code> (the equivalent of making input1 HIGH)

Wherever you have <code><pre><font size=2 face='Courier'>if pin1 = 1 etc... </font></pre></code> , replace it with <code><pre><font size=2 face='Courier'>if transistor = 1 </font></pre></code> (the equivalent of checking for a HIGH on input 1)
 

TEZARM

Senior Member
It sounds great Fowc but thats way beyond me to understand. I read what you are saying over and over again and have no idea how that works.
How can Input1 be low when Ouput0 is high, when there is no transistor that Output0 drives to make Input1 low? Could you please edit my code above so I can see what you mean and maybe try explaining to me again how it works cos you have lost me. Thanks
 

Fowkc

Senior Member
OK, first make sure you understand that in your circuit now, the state of input1 (HIGH or LOW) is entirely dependent on output0. When output0 is HIGH, input1 is LOW and vice-versa. So, each time you have
<code><pre><font size=2 face='Courier'>
if pin1 = 1
</font></pre></code>
It's exactly the same as saying
<code><pre><font size=2 face='Courier'>
if output0 = 0
</font></pre></code>
But you are in control of output0 through your code. At the moment, output0 in your circuit is being used <i>just like a variable </i> , like b0 or b1 or b2. So there's <i>no need to use the outputs and inputs at all </i> for this part of your alarm.

Let's take the first bit of your code, which I've modified:

<code><pre><font size=2 face='Courier'>
'b1 is a variable (either 1 or 0) that tells the PICAXE whether the alarm is ON or OFF, just as pin1 used to do
if b1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if b1=1 and pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if b1=1 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if b1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=0 then prechirp
if b1=1 and pin0=1 and pin7=1 and pin2=0 and pin6=1 then fulltrigger

alarmon: 'Turn Alarm System On
low 2 'Turn OFF Immobiliser
pause 200 'Wait 200 milli seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 100 'Wait 100 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 500 'Wait 500 Milli Seconds
high 5 'Pull Central Lock Motor
pause 500 'Wait 500 Milli Seconds
low 5 'Release Pulse To Central Lock Motor
pause 2000 'Wait 2 Seconds
high 1 'Turn On (-) When Armed Wire
high 7 'Turn On Status Led

b1 = 0 '&lt;----- make b1 the same as what input1 would have been

goto start

alarmoff: 'Turn Alarm System Off
low 1 'Turn Off (-) When Armed Wire
pause 200 'Wait 200 milli seconds
for b0=1 to 2 'Flash / Chirp 2 Times
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 100 'Wait 100 Milli Second
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 100 'Wait 100 Milli Seconds
next b0 'Ending To 2 Times Flash / Chirp
pause 500 'Wait 500 milli Second
high 6 'Pull Central UNLock Motor
pause 500 'Wait 500 milli Seconds
low 6 'Release Pulse To Central UNLock Motor
pause 1000 'Wait 1 Second
low 7 'Turn Off Status Led
pause 500 'Wait 500 milli Seconds
high 2 'Turn On Immobiliser
pause 200 'Wait 200 milli Seconds
for b1=1 to 3 'Flash / Chirp 3 Times for Immobiliser
high 3 'Turn On Parklights
high 4 'Turn On External Siren
pause 100 'Wait 100 milli seconds
low 3 'Turn Off Parklights
low 4 'Turn Off External Siren
pause 100 'Wait 100 Milli Seconds
next b1 'Ending To 3 Times Flash / Chirp
high 2 'Turn On Immobiliser

b1 = 1 '&lt;----- make b1 the same as what input1 would have been

goto start
</font></pre></code>

This is entirely software based - no inputs, no outputs, no transistor. The solution you had, feeding an output to an input was actually quite ingenious, but unnecessary.

Hope you understand this now. Run through the code and see how it works. If you don't (or it doesn't work!), we'll try again.
 

TEZARM

Senior Member
Fowkc, thanks so much mate. I will need a few hours to try and figure this out so I will get back to you soon. Thanks again.
 

BeanieBots

Moderator
Let me try.
when (whatever sets output 0 high)=1 then (whatever reads input 1) is low
Put simply, instead of testing the condition of input 1, you should be testing the condition of whatever you use to set output 0.
The vlaue of input 1 is nothing more than the inverse of the value of output 0.
YOU have set the value of output 0 so YOU already know the value of input 1.
What you have done is not so much incorrect, it is simply a waste of hardware.
 

TEZARM

Senior Member
Fowkc I can't get it to work. Also I have to use b7 cos b1 I have used already. But you might just be using that as an example for me I guess. I think I made a mistake in the code I posted. The first part should be like this, sorry about that.

if pin1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if pin1=1 and pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if pin1=0 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if pin1=0 and pin0=1 and pin7=1 and pin2=1 and pin6=0 then prechirp
if pin1=0 and pin0=1 and pin7=1 and pin2=0 and pin6=1 then fulltrigger
 

TEZARM

Senior Member
My inputs (buttons on my remote control) will not work at all now? Whats happening at the moment is the alarm is just looping and doing everything under alarmon: over and over again and by itself aswell. I cannot get the alarm to do anything myself.
 

TEZARM

Senior Member
This would be good to if it worked I think but not sure how to do it either?

if b7=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if pin0=1 and pin7=0 then b7
if pin0=0 and pin7=1 then b7
if pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if pin0=1 and pin7=1 and pin2=1 and pin6=0 then prechirp
if pin0=1 and pin7=1 and pin2=0 and pin6=1 then fulltrigger
 

Fowkc

Senior Member
When you say
<code><pre><font size=2 face='Courier'>
if pin0=1 and pin7=0 then b7
if pin0=0 and pin7=1 then b7
</font></pre></code>

What do you mean by the &quot;then b7&quot; part?

Can you post all your code again? I know it's going to be a long thread at this rate, but it might help. If the PICAXE is continually looping around <i>alarmon: </i> regardless, it sounds like none of the IF statement are ever TRUE. Therefore it will jump to the line afterwards, which is <i>alarmon: </i> .

If I have time, I'll draw a flowchart of your code when you post it. Then hopefully you'll be able to see how the flowhcarts work and how you can use them to understand and develop your program.

That's if I have time, I have a Solid State physics test tommorow that I really should pass :)
 

TEZARM

Senior Member
&quot;Fowkc said&quot;
When you say
if pin0=1 and pin7=0 then b7
if pin0=0 and pin7=1 then b7
What do you mean by the &quot;then b7&quot; part?

I don't know? It doesn't make any sense at all. I was just trying something but it's to hard for me anyway. Ok, heres my code again.

Please note: To get the code to work you need to change this line below to pin1=1. It should be pin1=0 but won't work this way because of this transistor problem.
if pin1=0 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff


'TEZARM'S CAR ALARM CODE

'LED = o/p7 'DOORS / FULL TRIGGER = i/p2
'UNLOCK = o/p6 'PRECHIRP = i/p6
'LOCK = o/p5 'ALARM ON/OFF RECOGNITION PIN INPUT = i/p1 ?????
'(-)WHEN ARMED = o/p1 'DISARM = i/p0
'PARKLIGHTS = o/p3 'ARM = i/p7
'EXT SIREN = o/p4 'ALARM ON/OFF RECOGNITION PIN OUTPUT = O/P0 ?????
'IMMOBILISER = o/p2 (N/O Relay)

start:


if pin1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if pin1=1 and pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if pin1=0 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if pin1=0 and pin0=1 and pin7=1 and pin2=1 and pin6=0 then prechirp
if pin1=0 and pin0=1 and pin7=1 and pin2=0 and pin6=1 then fulltrigger



alarmon: 'Turn Alarm System On
low 2 'Turn OFF Immobiliser
pause 200 'Wait 200 milli seconds
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 100 'Wait 100 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 500 'Wait 500 Milli Seconds
high 5 'Pull Central Lock Motor
pause 500 'Wait 500 Milli Seconds
low 5 'Release Pulse To Central Lock Motor
pause 2000 'Wait 2 Seconds
high 1 'Turn On (-) When Armed Wire
high 7 'Turn On Status Led
'HIGH 0 'TURN ON ALARM ON/OFF RECOGNITION PIN TRANSISTOR ?????
goto start

alarmoff: 'Turn Alarm System Off
low 1 'Turn Off (-) When Armed Wire
pause 200 'Wait 200 milli seconds
for b0=1 to 2 'Flash / Chirp 2 Times
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 100 'Wait 100 Milli Second
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 100 'Wait 100 Milli Seconds
next b0 'Ending To 2 Times Flash / Chirp
pause 500 'Wait 500 milli Second
high 6 'Pull Central UNLock Motor
pause 500 'Wait 500 milli Seconds
low 6 'Release Pulse To Central UNLock Motor
pause 1000 'Wait 1 Second
low 7 'Turn Off Status Led
pause 500 'Wait 500 milli Seconds
high 2 'Turn On Immobiliser
pause 200 'Wait 200 milli Seconds
for b1=1 to 3 'Flash / Chirp 3 Times for Immobiliser
high 3 'Turn On Parklights
high 4 'Turn On External Siren
pause 100 'Wait 100 milli seconds
low 3 'Turn Off Parklights
low 4 'Turn Off External Siren
pause 100 'Wait 100 Milli Seconds
next b1 'Ending To 3 Times Flash / Chirp
high 2 'Turn On Immobiliser
'LOW 0 'TURN OFF ALARM ON/OFF RECOGNITION PIN TRANSISTOR ?????
goto start


prechirp: 'Prechirp Wire For Sensors

for b2=1 to 5 'Flash / Chirp 5 Times for Prechirp
high 4 'Turn On External Siren
high 3 'Turn On Parklights
pause 200 'Wait 200 Milli Seconds
low 4 'Turn Off External Siren
low 3 'Turn Off Parklights
pause 200 'Wait 200 Milli Seconds
next b2 'Ending To 5 Times Flash / Chirp
goto start


fulltrigger:

high 4 'Turn On External Siren
pause 3000 'Scream Siren for 3 Seconds
low 4 'Turn Off Siren
goto start















 

Fowkc

Senior Member
OK, can't look it it right now, but I'll have a crack at it tommorow evening, unless someone else does.
 

TEZARM

Senior Member
Here is an example of what I am trying to work with at the moment but it won't work. Output 4 should ONLY go high if alarm is on but it also goes high when alarm is off to. Damn it!!

Why won't this work somebody?

Where's Hippy when I need him?
 

TEZARM

Senior Member
Oh yeh, the example might help aswell huh?

start:

b0=0

if b0=0 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if b0=0 and pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if b0=0 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if b0=0 and pin0=1 and pin7=1 and pin2=0 and pin6=1 then door

alarmon:

high 1
b0=0
goto start

alarmoff:

low 1
b0=1
goto start

door:
if b0=1 and pin2=1 then goto start
if b0=0 and pin2=0 then scream

scream:
high 4
pause 2000
low 4
goto start








 

TEZARM

Senior Member
Actually this one I like the best but it won't work either? Why not? Wat am I doing wrong guys?

start:

if pin1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start
if pin1=1 and pin0=1 and pin7=0 and pin2=1 and pin6=1 then alarmon
if pin1=1 and pin0=0 and pin7=1 and pin2=1 and pin6=1 then alarmoff
if pin1=1 and pin0=1 and pin7=1 and pin2=0 and pin6=1 then door

alarmon:

high 3
goto start

alarmoff:
low 3
goto start

door:
let pin1=0
goto scream
goto start

scream:
if pin1=1 then start
let pin1=0
high 4
pause 2000
low 4
goto start






 

Jeremy Leach

Senior Member
Haven't been following this thread, but statements like <i>if pin1=1 and pin0=1 and pin7=1 and pin2=1 and pin6=1 then start </i> can be handled perhaps more efficiently by working out a value representing the pins first. Like:

<code><pre><font size=2 face='Courier'>
Symbol PinValue = b0

PinValue = Pins AND %11000111
</font></pre></code>

Then use a CASE statement to take different actions depending on the value.

The AND just masks out the pins you're not interested in.
 
Top