Thread: Program C

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Program C


    Hi everybody

    I want to write a program in C language or algorithmic that change Value of integer "x"
    from 0--->333 then 333-->0 and repeat this action forever.

    Thank you :)
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    Cool! Good luck with that, and let us know how it works out for you!
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    Do you need a program that wastes cpu time (to use as a resource disrupting virus) or a program that doesn't return?
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    16
    Rep Power
    0
    I see, and is this program actually supposed to accomplish anything?
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    Here's half of it (kind of :p )
    Code:
    for ( int i = 0 ; i <= 0xdb ; i++ ) printf("%03o\b\b\b",i);
    Also cross-posted
    Apparently (since there's a nice picture there which we didn't get), the OP wants to generate a sawtooth wave.
    (content is in Arabic, so I used google translate).
    Last edited by salem; December 24th, 2012 at 01:36 AM.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0
    Hi,

    Yes I want to program a PWM signal (Pulse width modulation) and send it to DSP

    The objective is to varying brightness of the Led by changing variable x

    x = 333 ---> 100 % of brightness
    x= 166 ---> 50 % of brightness
    x= 0 ---> 00 % of brightness

    I want to increase brightness from 0% -----> 100% then decrease it from 100% -- 0%

    I'm using actually this program

    Code:
     while(1)
         	 {
               brightness++;
               TIM4->CCR3 = 333 - (brightness + 0) % 333; // set brightness
               Delay(0x11111);
             }
    But it doesn’t work like I want,
    This program work like this 0% ---> 100% then repeat the same think 0% ---> 100%


    Thank you :)
  12. #7
  13. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    So put both elements in your loop
    Code:
    while ( 1 ) {
       // code for 0% to 100%
       // code for 100% to 0%
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    As a single function:

    abs(166-brightness%333)
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by b49P23TIvg
    As a single function:

    abs(166-brightness%333)
    Thank you, the brightness in your program works from 50% ---> 0% ---> 50%

    I change it to 100% ---> 0% ---> 100% using this modification

    Code:
      abs(333-brightness%666)
    :trockon:

    Thank you for all responses :hi:

    Comments on this post

    • b49P23TIvg agrees : Whoops!

IMN logo majestic logo threadwatch logo seochat tools logo