Can any body code this in Arduino???
i want a infinite loop that can reach a
...certain value and print it continuously like
0,1,2,3.........255,255,255,255.... to infinity...
and
255,254,253,252.... 3,2,1,0,0,0,0,0,0,0.....to infinity...
plzzz help its urgent... Thanks.
a for loop followed by a while(1) will do the trick
sorry for being a noob... but can u share a sample code here???
i tried this code but nothing is doing...
if (option == '8' && speed1 == '5') {
for(conspeed=0 ; conspeed<255 ; conspeed++){
while(1){
analogWrite(pinl1, conspeed);
analogWrite(pinl2, 0);
analogWrite(pinr1, conspeed);
analogWrite(pinr2, 0);
delay(100);
}
}
}
That's a while loop inside a for loop.
You need the while after the for.
or (untested, uncompiled)
for(conspeed=0 ; 1 ; conspeed+= (conspeed <= 255) ? 1 : 0){
analogWrite(pinl1, conspeed);
analogWrite(pinl2, 0);
analogWrite(pinr1, conspeed);
analogWrite(pinr2, 0);
delay(100);
}
i did this
if (option == '8' && speed1 == '5') {
for(conspeed=0 ; 1 ; conspeed+= (conspeed <= 255) ? 1 : 0){
analogWrite(pinl1, conspeed);
analogWrite(pinl2, 0);
analogWrite(pinr1, conspeed);
analogWrite(pinr2, 0);
delay(100);
}
while(1){
}
}
actually i want to control motor speed from 0 to 255 when it read '5' from serial, the above code is running the motors from 0 to 255 for just one time... i want that when it reaches 255 it continuously get 255... plzz help..
this code is running
The following provides the requested result for your example value ranges. Should be easy for you to modify the start and end ranges.
#include <limits.h>
unsigned char counter = 0;
do
{
counter += ((counter != UCHAR_MAX) ? 1 : 0);
Serial.print(counter);
} while ( true );
unsigned char counter = UCHAR_MAX;
do
{
counter -= ((counter != 0) ? 1 : 0);
Serial.print(counter);
} while ( true );
@ lloyddean
your code ain't compiling in arduino IDE dont know y..
i did this
if (option == '8' && speed1 == '5') {
for(conspeed=0 ; 1 ; conspeed+= (conspeed <= 255) ? 1 : 0){
analogWrite(pinl1, conspeed);
analogWrite(pinl2, 0);
analogWrite(pinr1, conspeed);
analogWrite(pinr2, 0);
delay(100);
}
while(1){
}
}
actually i want to control motor speed from 0 to 255 when it read '5' from serial, the above code is running the motors from 0 to 255 for just one time... i want that when it reaches 255 it continuously get 255... plzz help..
this code is running
dont know y
Without you posting the error messages you're seeing and the code you've written, neither do we.
system
July 1, 2010, 7:54am
10
With analogWrite, whatever value was written last will remain in effect until some other value is written.
So for a ramp up (or down) function you simply run through a loop and write values from 0 to 255 with some delay between steps. Once you reach 255, you exit the loop and that's it.
tkbyd
July 1, 2010, 8:41am
11
The following "answer"...
a) Starts from scratch
b) Isn't EXACTLY Arduino code, but should give you the idea....
void setup()
{
integer iCounter=0;
}
void loop()
{
if (iCounter<256) {iCounter=iCounter+1;};
print iCounter;
}
(See also....
... Arduino programming course.)
system
July 1, 2010, 5:41pm
12
Thanks for all your support and help... I used this code and its working fine...
main()
{
int a=0;... See More
while(1)
{
printf("%d\n",a);
if(a<255)
a++;
}
}
system
July 1, 2010, 5:48pm
13
...which is virtually identical to reply #4 .