Shop OBEX P1 Docs P2 Docs Learn Events
how to hold a pin on HIGH — Parallax Forums

how to hold a pin on HIGH

Hey guys,
I tested out the blink code for the propeller and I found out that the function that sets a pin high is different for the prop than from the one for the Arduino.
What I'm saying is, for the Arduino, digitalWrite(PIN, HIGH) sets the pin high and stays high. However, for the propeller, something like high(PIN) sets the pin high but after a fraction of a second goes down to low again. Is there any way to make the pin stay on high for the propeller?

Thanks!

Comments

  • Does anything come after the high(pin)? If not, the cog will stop when main returns and then the pin will go low again. Try adding an infinite loop after your code, or try putting your code in an infinite loop.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2018-01-30 03:35
    When something doesn't work properly you can be sure something is broken. But because it does not seem logical for a tested library function to "reset" a high then logically the part that is broken is yours. However how do you expect anyone to help if you don't post your complete code. More than likely "your code" is reseting or the cog stops etc. Make sure that after you paste your code that you select that section and click the "C" code tag icon at the top of the post. Otherwise you can zip it and attach it as a file.
  • Its like any other microcontroller, once you set a pin it stays set until something changes it. However note that there are more
    things (cogs) that can change things - so another cog could be doing something with the pin, or if the cog responsible for driving the pin exits it disconnects from the pin completely at that point.
  • twm47099twm47099 Posts: 867
    edited 2018-01-31 14:23
    Please post your existing code. However, as others have mentioned it sounds like the program is ending, which will stop the propeller and turn off the led.

    If you are using C, put the following line after high(pin)
    while(1);
    
    That will keep the program running until either the reset button is pressed or power to the propeller is disconnected.
  • picopico Posts: 29
    edited 2018-01-31 16:42
    super simple code, got it from here: https://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-circuits/blink-light

    /*
    Blink Light.c

    Blink light circuit connected to P26.
    */

    #include "simpletools.h" // Include simpletools

    int main() // main function
    {
    while(1) // Endless loop
    {
    high(26); // Set P26 I/O pin high
    pause(1000); // Wait 1/10 second
    low(26); // Set P26 I/O pin low
    pause(1000); // Wait another 1/10 second
    }
    }

    I simply uploaded this simple c program to my propeller board, and rather than having the LED on and then off, it flashes every second. Kinda like what would happen if I hooked up a button between the LED and the power source and I'm clicking the button every second. You know what I mean?
  • Unless I am very much mistaken, this program will endlessly cycle the P26 led one second on, one second off. The 1/10 second comments are incorrect.
  • oh yeah I'm aware of that, I just modified the code to make the blinking slower. I was too lazy to fix the comments.
  • Oh, it turns out that LED30(I was using 30 cuz it was built into the board) is used by another cog, or at least it seems.

    I think it is used by the serial protocol. I hooked the LED up to P2 and it works fine!

    Thanks!
  • Cluso99Cluso99 Posts: 18,069
    Yes, typically P31 & P30 are used for the serial interface usually connected to USB and PC via a PropPlug or equivalent circuit.
Sign In or Register to comment.