9 years, 10 months ago.

does anyone can help me,please><(about use "if")

http://developer.mbed.org/users/changzhe8387/code/S8100B/

this is my code, i do not know the reason of error,please tell me what is the mistake. thank you very much

1 Answer

9 years, 10 months ago.

-A little different than Arduino, you should define your variables outside your main.

#include "mbed.h"
Serial pc(USBTX, USBRX);
PwmOut pwm1(p21);
PwmOut pwm2(p22);

    int y=600;
    int x=500;
    int f;
    
int main(){
  while(1)
  if(x-y>0){
    for(f = 1000;f < 3000;f+=10);
    pwm1.pulsewidth_us(f);
    }else if(x-y<0){
        for(f = 1000;f <2000;f+=10);
        pwm2.pulsewidth_us(f);
    }
  }

Accepted Answer

thank you very much. i have reolution this problom

posted by jyo tetsu 20 Jan 2015