Thursday, November 7, 2024

Challenge 1 - Photoresistors

I'm making this its own post because I don't think I'm actually going to get to try it out "for real," because I looked and looked and can't find a photoresistor in my kit!  Unless I can find one, I'm just going to have to be happy with the Tinkercad model.

This was definitely way harder, and I had to look online for advice.  I finally found some code and a way to get things wired up, but it was doing all kinds of things "the easy way," which really confused me because it was hiding the math - I kept thinking, what is this loop() or constrain() function???  (Spoiler: they adjust a range of numbers from one scale to another, which I feel much better just doing myself.)




The code is in the model as well as the layout, but my intention had been to get the photoresistor working, then the thermal sensor, then the potentiometer again, and then pull everything together as suggested in the challenge.  

These are the critical lines of the code:

  lightLevel = analogRead(sensorPin);
   
  Serial.println("OG lightLevel");
  Serial.println(lightLevel);  
 
  lightLevel = (lightLevel - low)/range * 255;

where 

int lightLevel, low = 54, high = 974;

are declared as global constants.

Since I don't have a photoresistor, I'm going to play around and see if I can come up with another idea for an extension, but I at least wanted to get this attempt documented in case I find one later!





No comments:

Post a Comment

Nooooo, don't make me reflect on my learning!

 ... I just want to stick wires in breadboards and make froggies dance!!! Okay, but seriously, that stupid dancing frog was clearly my most ...