So the task was to create some light objects, assign each object to an LED light connected to the arduino, and then later on be able to control which light becomes active with a couple of push buttons.
int *on = 2;
class Lights{
public:
int identity;
bool light_Up() /* Returns true if the light is flashing*/{
while(identity == on){
pinMode(OUTPUT, identity+3);
while(true){
digitalWrite(identity+3, HIGH);
delay(500);
digitalWrite(identity+3, LOW);
delay(500);};
return true;}
return false; };
Lights(int x) /* Sets the identity and starts the blinking*/{
this->identity = x;
light_Up();
};
};
void setup() {
// put your setup code here, to run once:
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT);
Serial.begin(9600);
Serial.println("Serial begin");
Serial.println(digitalRead(9));
for (int i = 0; i<3; i++){
Lights ptrLight = new Lights(i);
};
}
void loop() { // Nothing in here runs, at all.
Serial.println(digitalRead(9));
delay(2000);
}
The offending piece seems to be the for loop inside void setup(). If I delete this, then the loop() works totally fine, but I'm just not understanding why?
If I move the for loop to the very top of void setup(), then nothing will run at all, so there's something dodgy about the loop. I mean it works, and I get the correct LED flashing so it is working as intended, but nothing after the loop will run at all.
PS, I apologize for the horrific code. I'm not an expert.