Open Source Some questions on what arduino can do - very simple nothing too technical

Discussion in 'Software' started by shigllgetcha, 10 Aug 2011.

  1. shigllgetcha

    shigllgetcha Come at me bro

    Joined:
    3 Mar 2008
    Posts:
    2,031
    Likes Received:
    87
    Ive used an arduino before but I didnt do the coding for it.

    Can an arduino monitor an input and only run a certain script when it changes (a 5v in as PWM and do one action when it goes form 5v to 0v and a different action when it does the opposite).

    If this is possible, would the cycle only involve checking the input every say 1 min and not run all the other code until it changes.

    So basically with A as the input
    when A goes from 5v to 0v then do X (or just when it goes to 0v)
    when A goes from 0v to 5v then do Y (or just when it goes to 5v)

    This might be a very fundamental question now that ive written it down
     
  2. shigllgetcha

    shigllgetcha Come at me bro

    Joined:
    3 Mar 2008
    Posts:
    2,031
    Likes Received:
    87
    Just thinking the input would be a constant 5v, dont think thats a PWM though
     
  3. wyx087

    wyx087 Homeworld 3 is happening!!

    Joined:
    15 Aug 2007
    Posts:
    11,301
    Likes Received:
    426
    arduino are basically AVR's. so it's very easy to code for.

    two ways of doing this: pooling or interrupt.

    -pooling:
    flagX, flagY.
    while{
    if A = 0v then do X, raise flagX, lower flagY
    if A = 5v then do Y, raise flagY, lower flagX
    }

    -interrupt:
    set A as interrupt input (interrupt only triggers on change, IIRC.
    ISR{
    when A = 0v then do X
    when A = 5v then do Y
    }


    of course, i could be talking rubbish. i've coded for AVR's, and i've read Arduino uses AVR as its programmable processor.
     
    thehippoz likes this.
  4. shigllgetcha

    shigllgetcha Come at me bro

    Joined:
    3 Mar 2008
    Posts:
    2,031
    Likes Received:
    87
    double poster
     
  5. shigllgetcha

    shigllgetcha Come at me bro

    Joined:
    3 Mar 2008
    Posts:
    2,031
    Likes Received:
    87
    Ah this could be it, think this would work for what I want. thanks
     
    Last edited: 10 Aug 2011
  6. wyx087

    wyx087 Homeworld 3 is happening!!

    Joined:
    15 Aug 2007
    Posts:
    11,301
    Likes Received:
    426
    quick google showed up this:
    http://gonium.net/md/2006/12/20/handling-external-interrupts-with-arduino/

    the code in AVR-GCC tutorial link at the end looks very familiar to me. it seems Arduino uses a non-standard C, which enforces a healthy coding structure. AVR is indeed the programmable chip, which uses GCC compiler and takes standard C (good coding structure will look very similar to Arduino's code, except most things are in Main, loops have to be done manually).
     
  7. shigllgetcha

    shigllgetcha Come at me bro

    Joined:
    3 Mar 2008
    Posts:
    2,031
    Likes Received:
    87
    To the best of your knowledge I can use an interrupt to run any script that the board would run.
     
  8. wyx087

    wyx087 Homeworld 3 is happening!!

    Joined:
    15 Aug 2007
    Posts:
    11,301
    Likes Received:
    426
    yes, interrupt service routines are just a built-in function that will run when the set trigger happens. it's same as any other function you write.
     

Share This Page