Shop OBEX P1 Docs P2 Docs Learn Events
Led's switch — Parallax Forums

Led's switch

Jimm2Jimm2 Posts: 16
edited 2010-01-30 10:12 in Propeller 1
When I push down on the switch (pin 23) and hold it down. All the led's go on, then when I let go of the switch, the led's go [noparse][[/noparse]0..19] goes left to right and then off. Is there A way to just turn off the led's? And not let them go the (left to right led's). Is there A way I can put in A [noparse][[/noparse]goto100] and go to the end of the (left to right Led's). After all the led's are switch off.

So: (switch [noparse][[/noparse]0..19] are turned on)........(switch is off [noparse][[/noparse]0..19] are off)
So: (switch is turned on and off, on and off [noparse][[/noparse]0..19] go left to right) (switch is off [noparse][[/noparse]0..19] are off)


The next thing is I hold down on the switch and let go of the switch. I let the chip sit, for A bit and then [noparse][[/noparse]0..19] goes (left to right) come on sometime and turn off sometimes. Why is this doing this and what can I do to stop it?




Here is the Program...........................




CON
     _clkmode = xtal1 + pll16x
     _xinfreq = 1_000_000


LEDpin1 = 0 
LEDPin2 = 17
SwitchPin = 23



OBJ   led: "LEDBlink"
Var

long    LastSwitchChange
long    RateThreshold
long    LastCNTValue
long    ResultCNT
byte    SwitchStatus


Pub start

Dira[noparse][[/noparse]LEDPin1]~~
Dira[noparse][[/noparse]LEDPin2]~~
Dira[noparse][[/noparse]SwitchPin]~

RateThreshold := 000_500_000
LastCNTValue := cnt

repeat
  ResultCNT := cnt - LastCNTValue  

  if Ina[noparse][[/noparse]SwitchPin] <> SwitchStatus       'is the state of the switch different from the last time it changed?
    LastCNTValue := cnt                   'lets record this time
    SwitchStatus := Ina[noparse][[/noparse]SwitchPin]        'store this as the current switch status
    
  if ResultCNT > RateThreshold            'we have gone over our threshold with no change in the SwitchStatus

                                             'this means either the switch was held down or not pressed
    outa[noparse][[/noparse]LEDpin1]~   

           
    If SwitchStatus == 1        'Switch was held
               
      outa[noparse][[/noparse]LED.down]~~
    
      
    else                        'switch was not pressed
         
      
      outa[noparse][[/noparse]LEDpin2]~ 
    

    
                                        'the switch is changing faster than the threshold r
  else                                    'the switch is changing faster than the threshold rate
      
   outa[noparse][[/noparse]LED.turn]~~











PUB Turn



dira[noparse][[/noparse]0..19] := %11111111111111111111
outa[noparse][[/noparse]0..19] := %11111111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %01111111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00111111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00011111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00001111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000011111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000001111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000011111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000001111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000011111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000001111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000000011111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000000001111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000000000111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000000000011
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000000000001
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000000000000
waitcnt(clkfreq/4 + cnt)





PUB Down

dira[noparse][[/noparse]0..19] := %11111111111111111111
outa[noparse][[/noparse]0..19] := %11111111111111111111
waitcnt(clkfreq/4 + cnt)
outa[noparse][[/noparse]0..19] := %00000000000000000000


Comments

  • BradCBradC Posts: 2,601
    edited 2010-01-30 02:54
    Isn't this about the 695th time you've posted this same bit of code?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life may be "too short", but it's the longest thing we ever do.
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-01-30 10:12
    Hello Jimm,

    I want to explain HOW you have to write postings that you get answers.

    1.) Clear and simple words. I have 25 years experience as a hobby programmer.
    I have to read and re-read and re-read again and again your description TRYing to understand what you mean.
    And Im still NOT sure if I understand it right.

    Please use simple words to describe what you want to achieve.
    Don't mix the explanation what you want to achieve with things that are happening.
    First thing: describe 100% PURE how should it work if everything works as you WANT it to work.

    If you write things like "switch [noparse][[/noparse] 0..19 ] are turned on" I don't understand it. Should there be 20 switches numbered from 0..19 ???
    or are 0..19 Prop-IO-pin-OUTPUTs that should be switched on - by what ????

    ..."And not let them go the (left to right led's)" --- what do you mean by that???

    It is not really clear!

    So my recomendation is to define EASY to understand identifiers for the different parts of your program and identifiers that are SELF-EXPLAINING

    example:
    ControlButton23 'a mechanical button that connects propeller-IO-pin number 23 to +3.3V when pressed and is left opened when not pressed

    propeller-IO-pins number 0..19 conneted to LEDs to switch on/off the LEDs through the program

    If ControlButton23 is pressed and held down for minimum 1 second, ALL LEDs 0..19 should be turned ON

    If ControlButton23 is UNpressed for minimum 1 second, ALL LEDs 0..19 should be turned OFF

    If ControlButton23 is pressed and released, pressed and released continuosly where each press and release lasts SHORTER than 1 second
    The LEDs should be turned OFF one after each other in a certain pattern.

    Attaching code that has more then 10 lines you should use the attachment manager.
    Click on the picture below to see how this is done

    What I assume what you need is a repeat-loop that is CONTINUOSLY detecting if

    1.) button is left alone
    2.) button is pressed down continoulsy
    3.) button is pressed down and released continously

    depending on result 1, 2 or 3 different actions have to be done

    there is no command GOTO in SPIN (and me personally I'm VERY glad that there is no goto)

    the turn on/off of the LEDs (=LED-sequence) can be done using a program-technique called "statemachine"
    wich allows to interrupt the LED-sequence at any point and switch over to ALL LEDs on or ALL LEDs off

    Before I may write code-segments to show this YOU have to confirm or correct my understanding of what you want to do
    IN CLEAR and EASY to understand words

    best regards

    Stefan

    P.S: the executing of the LED-sequence if you leave the button alone might be caused by the lack of a Pull-down-resistor between Propeller-IO-Pin 23 and ground

    Post Edited (StefanL38) : 1/30/2010 11:12:04 AM GMT
Sign In or Register to comment.