EmbDev.net

Forum: µC & Digital Electronics c++ object of an output (LED)


von micro u. (Guest)


Rate this post
useful
not useful
hi
im looking for some simple solution for my output class led.
momentary, im buildung my own litte library for simple avr applications 
for beginner.

first class will be used to set up an led object like this:
1
#ifndef CLED_H_
2
#define CLED_H_
3
4
5
class CLED
6
{
7
    short pL, pN;
8
    public:
9
    //constructor
10
    LED(){
11
    }
12
    //methods
13
    void ini(){
14
    // ...
15
    }
16
    void toggle(){
17
    // do something
18
                }
19
    void turnOn(){
20
                // do something
21
    }
22
    void turnOff(){
23
                // do something
24
    }
25
}; //CLED
26
27
28
#endif /* CLED_H_ */

main.cpp
1
DDRC |=  ((1 << PC0);



im looking for a solution, for the constructor or an ini method, 
whatever works.
when you generate the object, you add some paramaters (eq.: B 3 (PortB 
Pin3)) and then, when i finally control the object, it knows itself, 
where to rout the signal.

eg:
generate the object:
CLED ledRed("B", 3);

control it:
ledRed.toggle();

von Tom (Guest)


Rate this post
useful
not useful
Andreas Ferber did some template magic which does approx. what you are 
planning to do. As a bonus the compiler can remove all of the overhead 
of the class: Beitrag "IO-Register als Template-Parameter"

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.