0

Im trying to make an LED that breathes. This is the code I currently have. When I run it it gets to the point where it prints "breath off", then gets stuck and I have to pull the plug. It doesnt ever enter the for loop(tested already), and it is connected to gpio 18. Anyone have any idea why it is doing this?

pinMode(LEDPIN,PWM_OUTPUT);
     printf("|   breath off    |\n");
     for(bright=0;bright<1024;++bright){
        pwmWrite(LEDPIN,bright);
        delay(2);
        }
     printf("|    breath on    |\n");
     for(bright=1023;bright>=0;--bright){
        pwmWrite(LEDPIN,bright);
        delay(2);
        }
return 0;}

enter image description here

0

I suspect this is an unwanted feature (perhaps a bug) within wiringPi.

If you use GPIO18 for PWM wiringPi assumes you want to use hardware PWM and tries to program the hardware PWM peripheral. However unless run as root wiringPi has no access to this hardware and will crash.

A workaround is to run your program as root, i.e. precede the command with sudo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.