Wacky for loop behaviour

Can someone please explain what is going wrong in my code?
int Ledpin = 30;
int Ledpin1 = 32;
int Ledpin2 = 34;
int input = 22;
int time = 1000;
int pwm = 0;

void setup(){
pinMode(22, INPUT);
for (int i = 30; i<=35; i++){
pinMode(i,OUTPUT);
digitalWrite(i,LOW);}
}

void loop(){
if(digitalRead(input) == 0){
for (int a = 30; a<=35; a+=2){
for(int c=0; c<=(1000); c+=1){
digitalWrite(a,HIGH);
delayMicroseconds(c10);
digitalWrite(a,LOW);
delayMicroseconds(10000-(c
10));
}
for(int b=0;b<=1000; b+=1){
digitalWrite(a,HIGH);
delayMicroseconds(10000-(b10));
digitalWrite(a,LOW);
delayMicroseconds(b
10);
}
}
}
}

I am trying to use a digital pin as a pwm output, and right before switching to the next pin when the pin reaches its max or minimum brightness, It will flash off or on and then continue with the code normally. Aside from this, the code is working exactly as I expected it would. Anyone know what could be causing this?

To post your code use the # sign.

I changed your for loops because you had it going to 35 but, you only list up to pin 34 as an output pin. Maybe that is part of your issue. I also added white space and used autoformat in the Arduino IDE to make the code easier to read.

I don't understand the purpose of your code but, maybe I fixed it by working on the for loops. Test it out and see if you can better describe your problems.

int Ledpin = 30;
int Ledpin1 = 32;
int Ledpin2 = 34;
int input = 22;
int time = 1000;
int pwm = 0;

void setup()
{
  pinMode(22, INPUT);

  for (int i = 30; i < 34; i += 2)
  {
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
  }
}

void loop()
{
  if(digitalRead(input) == 0)
  {
    for (int a = 30; a < 34; a += 2)
    {
      for(int c = 0; c <= 1000; c += 1)
      {
        digitalWrite(a,HIGH);
        delayMicroseconds(c*10);
        digitalWrite(a,LOW);
        delayMicroseconds(10000 - (c*10));
      }

      for(int b=0; b <= 1000; b += 1)
      {
        digitalWrite(a,HIGH);
        delayMicroseconds(10000 -(b * 10));
        digitalWrite(a,LOW);
        delayMicroseconds(b * 10);
      }
    }
  }
}

You didn't fix the for loops, you broke them.
For example, this

for (int a = 30; a < 34; a += 2)

will only go through the loop for a=30 and 32, whereas the original

for (int a = 30; a<=35; a+=2){

goes through for a=30,32,34

Pete

I think your issue may be the zero-length delays in the for loops.

When c=0, you will have a delay(0); in this section, for example:

for(int c=0; c<=(1000); c+=1){
digitalWrite(a,HIGH);
delayMicroseconds(c*10);

I seem to remember having a similar issue some time and deciding that zero length delays were a bad plan.

You could try:

for(int c=0; c<=(1000); c+=1){
digitalWrite(a,HIGH);
delayMicroseconds(c*10+1);

for an imperceptibly different but non-zero delay.

Awesome! It works perfectly now. Thanks so much!