--- In oopic@yahoogroups.com, "Mike Martin" <mikemartin@...> wrote:
>
> Hi Dave - well it's too simple. All I'm trying to do is to emulate a
simple
> push button on/off switch. I have an oLED object and an oSwitch
object and
> I'm using a C.1.X chip and the OOPic 6 compiler. All I have is a
simple LED
> and a board-mount micro-switch that I bought from the local Tandy store
> (normally off). My code works perfectly and I can turn on the LED in
code
> but the moment I introduce oSwitch into the code the LED comes on
and stays
> on and the state off the switch seems to be ignored. My code is an exact
> copy of the code on the website - and everything seems to be wired
up OK. It
> just doesn't work.
>
>
>
> Dim Fred As New oSwitch
> Dim Bob As New oLED
>
> Sub Main()
> Bob.IOLine = 8
> Fred.IOLine = 9
> Do
> If Fred.IsOn Then
> Bob.TurnOnBright
> Else
> Bob.TurnOnDim
> EndIf
> Loop
>
> End Sub
>
>
Let's assume the code works and that, as far as the OOPic is
concerned, the input is ON. Check with pin voltage with a voltmeter
while toggling between on and off.
I wouldn't use the schematic shown for oSwitch. I am allergic to
solid connections to either +5V or ground. If I make the mistake of
defining the pin as an output, I will short it through the switch and
probably destroy the chip.
So, I would first add
OOPic.PullUp = cvOn as the second executable statement.
I would ALWAYS add
OOPic.Delay = 5000 as the first... (use 500 for V5 of the IDE)
Then I would connect a 330 ohm resistor between the pin and the switch
(normally open) and connect the other side of the switch to ground.
This way the resistor limits the pin current regardless of how I
define it.
Then, failing to get it to work with the new objects, I would rewrite
it as:
Dim LED as new oDIO1
Dim Switch as new oDIO1
sub main()
OOPic.Delay = 5000 ' 5 second startup delay
OOPic.PullUp = cvOn ' pull up resistors on IOLines 8..15
LED.IOLine = 8
LED.Direction = cvOutput
Switch.IOLine = 9
Switch.Direction = cvInput
Do
LED = Switch
loop
end sub
Of course, I have blown off the dimming capability and inverted the
sense of LED. I am assuming the LED is connected through a resistor
to +5V. So, the LED IOLine needs to go to 0 to turn on the LED and
the switch input should go to 0 when the switch is turned on (pulls
the pin to ground).
Now that the simple things work, try the new objects. Later, try the
oWire object and get rid of that Do-Loop.
Add to the declarations
Dim Wire as new oWire1
Then add to the code
Wire.Input.Link(Switch)
Wire.Output.Link(LED)
Wire.Operate=cvTrue
You may need to tweak the links for the new objects, I am not in a
position to check this at the moment.
Richard
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/oopic/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/oopic/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/