So, I’m somewhat new to mbed and wanted to try using a class with global pins.
The project is about a traffic-light-system with multiple traffic lights. So, my thought was to create a class “TrafficLight” and create multiple objects from that class.
The lights are obviously pins, but I want to declare different pins for different objects, but I have the error “Constructor for ‘TrafficLight’ must explicitly initialize the member ‘_redLight’ which does not have a default constructor”
My class:
class TrafficLight{
public:
DigitalOut _redLight;
DigitalOut _yellowLight;
DigitalOut _greenLight;
TrafficLight(PinName red, PinName yellow, PinName green){
_redLight = DigitalOut(red);
_yellowLight = DigitalOut(yellow);
_greenLight = DigitalOut(green);
}
};
And my idea is to say like:
TrafficLight trafficLight(ARDUINO_UNO_D10, ARDUINO_UNO_D9, ARDUINO_UNO_D8);
...
main(){
trafficLight._redLight = 1;
}
but the Constructor gives the error as before mentioned.
Any ideas, how to correct this?