Hello everyone.
I am trying to right a library for some LEDs functions. I put 26 LEDs (from p5 to p30) and I can change the brightness of everyone (thanks to a library allowing a pwm signal on each pins). Unfortunatly I now have c++ syntax issues to write my library of functions. You can find below the simple function "on", but I think ;y first issue comes from the syntax of the LEDFunctions::LEDFunctions thing.
/media/uploads/PA/led.zip
The Main.cpp:
- include "mbed.h"
- include "LEDFunctions.h"
- include "UniPWM.h"
m = new LEDFunctions ();
int main() {
while(1){
m.on(1, 10, 0.8, 0); /*on(led id, duration (s), brightness (0.00 < x < 1.00), smoothness (1 < x < 10))*/
}
}
The LEDFunctions.cpp :
- include "mbed.h"
- include "LEDFunctions.h"
- include "UniPWM.h"
- include <string>
- include <iostream>
- include <sstream>
using namespace std;
LEDFunctions::LEDFunctions(PinName pin) : _pin(pin){
}
void LEDFunctions::id(int n){
char *p = "UniPWM led(p";
char *p2 = ");";
stringstream ss (stringstream::in | stringstream::out);
ss << p << n << p2;
ss.str();
}
void LEDFunctions::brightness(float b){
_pin = UniPWM.duty(b);
}
void LEDFunctions::on(int n, int d, float b, float s){
id(n);
if(s > 1){
for(k = 0; k = b; k = b/s){
p = p + b/s;
led.brightness(p);
wait(0.1);
}
for(i = b; i < d; i += 0.1){
led.brightness(b);
wait(0.1);
}
}
else{
for(i =0; i = d; i += 0.1){
led.brightness(b);
wait(0.1);
}
}
}
and the LEDFunctions.h :
- ifndef MBED_LEDFunctions_H
- define MBED_LEDFunctions_H
- include "mbed.h"
class LEDFunctions{
public:
LEDFunctions(PinName);
void on(int, int, float, float);
private:
DigitalOut _pin;
void id(int);
float i;
float k;
float p;
void brightness(float);
};
- endif
I'd really appreciate some tips on the syntax, if you manage to understand what I already wrote ! Thank you very much.
By the way what is the command to quote code ? I'm sorry I copied it like that : /
Hello everyone.
I am trying to right a library for some LEDs functions. I put 26 LEDs (from p5 to p30) and I can change the brightness of everyone (thanks to a library allowing a pwm signal on each pins). Unfortunatly I now have c++ syntax issues to write my library of functions. You can find below the simple function "on", but I think ;y first issue comes from the syntax of the LEDFunctions::LEDFunctions thing.
/media/uploads/PA/led.zip
The Main.cpp:
m = new LEDFunctions ();
int main() {
while(1){
m.on(1, 10, 0.8, 0); /*on(led id, duration (s), brightness (0.00 < x < 1.00), smoothness (1 < x < 10))*/ } }
The LEDFunctions.cpp :
LEDFunctions::LEDFunctions(PinName pin) : _pin(pin){ }
void LEDFunctions::id(int n){ char *p = "UniPWM led(p"; char *p2 = ");"; stringstream ss (stringstream::in | stringstream::out); ss << p << n << p2; ss.str(); }
void LEDFunctions::brightness(float b){ _pin = UniPWM.duty(b); }
void LEDFunctions::on(int n, int d, float b, float s){ id(n); if(s > 1){ for(k = 0; k = b; k = b/s){ p = p + b/s; led.brightness(p); wait(0.1); } for(i = b; i < d; i += 0.1){ led.brightness(b); wait(0.1); } } else{ for(i =0; i = d; i += 0.1){ led.brightness(b); wait(0.1); } } }
and the LEDFunctions.h :
class LEDFunctions{
public: LEDFunctions(PinName); void on(int, int, float, float);
private: DigitalOut _pin; void id(int); float i; float k; float p; void brightness(float); };
I'd really appreciate some tips on the syntax, if you manage to understand what I already wrote ! Thank you very much.
By the way what is the command to quote code ? I'm sorry I copied it like that : /