When I upload the here included code mbed hangs.
If I change P20 to p22 it works like a charm.
#include "mbed.h"
PwmOut myled1(LED1);
PwmOut myled2(LED2);
PwmOut myled3(LED3);
PwmOut myled4(LED4);
InterruptIn Plus(p21);
InterruptIn Min(p20);
float LedSpeed=0.01;
void LedDim(float speed, PwmOut LedName)
{
for(float p = 0.0f; p < 1.0f; p += 0.02f) {
LedName = p;
wait(speed);
}
for(float p = 1.0f; p > 0.0f; p -= 0.02f) {
LedName = p;
wait(speed);
}
}
void PlusSpeed() {
LedSpeed -= 0.0005;
myled1 = 1;
myled1 = 0;
if (LedSpeed < 0)
{
LedSpeed=0;
}
}
void MinSpeed() {
LedSpeed +=0.0005;
myled4 = 1;
myled4 = 0;
//LedSpeed -= 0.001;
}
int main() {
Plus.rise(&PlusSpeed);
Min.rise(&MinSpeed);
while(1) {
LedDim(LedSpeed,myled1);
LedDim(LedSpeed,myled2);
LedDim(LedSpeed,myled3);
LedDim(LedSpeed,myled4);
LedDim(LedSpeed,myled3);
LedDim(LedSpeed,myled2);
}
}
When I upload the here included code mbed hangs.
If I change P20 to p22 it works like a charm.
#include "mbed.h"
PwmOut myled1(LED1);
PwmOut myled2(LED2);
PwmOut myled3(LED3);
PwmOut myled4(LED4);
InterruptIn Plus(p21);
InterruptIn Min(p20);
float LedSpeed=0.01;
void LedDim(float speed, PwmOut LedName)
{
for(float p = 0.0f; p < 1.0f; p += 0.02f) {
LedName = p;
wait(speed);
}
for(float p = 1.0f; p > 0.0f; p -= 0.02f) {
LedName = p;
wait(speed);
}
}
void PlusSpeed() {
LedSpeed -= 0.0005;
myled1 = 1;
myled1 = 0;
if (LedSpeed < 0)
{
LedSpeed=0;
}
}
void MinSpeed() {
LedSpeed +=0.0005;
myled4 = 1;
myled4 = 0;
//LedSpeed -= 0.001;
}
int main() {
Plus.rise(&PlusSpeed);
Min.rise(&MinSpeed);
while(1) {
LedDim(LedSpeed,myled1);
LedDim(LedSpeed,myled2);
LedDim(LedSpeed,myled3);
LedDim(LedSpeed,myled4);
LedDim(LedSpeed,myled3);
LedDim(LedSpeed,myled2);
}
}