Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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); } }