Automatic counter-Encoder
Hi everyone, I dont know much about programming so please help me out. Thanks!
Im looking for a way to make a counter that counts from 1-30 or 0-29. A total of 30 units. I have a clicker hooked up to a wheel and everytime the wheel moves 12 degrees i get a steady 1 or a steady 0 at the digital input. A total of 15x 0's and 15x1's willl be observed. I need a code that adds 1 everytime the input changes.
Starting with 0 , 1 , 0, 1, 0 , 1 , 0, 1, 0 , 1 ...etc
The counter: 1 +1 + 1+1+1+1 +1 +1 +1 +1 each time...and then everytime a 1 has been added, it keeps that value, untill the next 1 gets added.
Example: I can retrieve a number from the counter and if the number is 23, i make the PWM = 127, when the number is 24, i make the pwm = 135....etc
When the number reaches 29 or 30 depending if you started with 0 or 1, the next digit 30 or 31 does not exist and automatically resets to 0 and starts all over again....
Please point me in the right direction. My knowledge of C is limited to what I've been able to understand from examples and IFI mini RC programming guides.
Yes, I am using the Mini RC, EDU controller.
|