Simple program is erratic?
Iguanaman
Posts: 32
in Propeller 1
VAR
byte Button
PUB ButtonLED
dira[15]:= %1
dira[6]:= %0
repeat
if Button== 0
if ina[6]== 0
if Button== 1
if ina[6]== 1
!outa[15]
Here is my program using one push button to turn a LED on and off. Some times it works and some times it douse not? Button is P6. LED is P15.
Thank you for any improvements that anyone might give. Still reading all the forms from start to finish. Lots of information!!! 30 aug 2019(fri)
byte Button
PUB ButtonLED
dira[15]:= %1
dira[6]:= %0
repeat
if Button== 0
if ina[6]== 0
if Button== 1
if ina[6]== 1
!outa[15]
Here is my program using one push button to turn a LED on and off. Some times it works and some times it douse not? Button is P6. LED is P15.
Thank you for any improvements that anyone might give. Still reading all the forms from start to finish. Lots of information!!! 30 aug 2019(fri)
Comments
You have to take care of indentation. If you post code, use the [codx][/codx] tags ( replace codx by code )
I did not build a circuit to test this code but I'm pretty sure it will work.
Also, the variable Button is never changed so it's not necessary.
When a switch or push button is operated, the contacts will switch on/off intermittently many times over a very short instant of time. So your program needs to take care of this. The simplest way is with a timer. So, try this...
If you shorten the repeat loop count (which is used a a simple delay) you may see the LED change state when the switch is pushed. This will be erratic since it depends on how many state changes the code sees when you press it.
BTW I have assumed the switch has a pullup resistor to 3V3 and the switch is to ground. (a value > 1K would work so 10K would be nice).