Unlike the previous projects, I was initially stumped on what to do for this project, and wanted to avoid being over-ambitious. The idea I cam up with that was somewhat interesting was actually to have the LED read itself. Obviously, this could be done internally by the software, but I set up the photo-resistor right next to the led, and set the interval for blinks to decrease at a rate mapped from the reading on the photo-resistor. I also set up up to automatically calibrate so that all values that corresponded to just ambient light are ignored. My personal code from last class was giving my confusing bugs and was becoming a bit of a mess, so I instead modified the blink without delay example file from arduino.
const int ledPin = 2; const int photoresistor= A1; int ledState = LOW; unsigned long previousMillis = 0; const long initialInterval= 1000; long interval = initialInterval; int backgroundIntensity= 0; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, ledState); backgroundIntensity= analogRead(photoresistor)*1.05; Serial.begin(9600); } void loop() { unsigned long currentMillis = millis(); interval= (interval- abs(constrain(map(analogRead(photoresistor),backgroundIntensity,1023,0,10),0,10))); if(interval<=0){ interval= initialInterval; } Serial.println(interval); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; ledState=! ledState; digitalWrite(ledPin, ledState); } }