Coding the photoresistor values and setting up ports
This section shows how to code a Blue Pill application for reading data from a photoresistor.
The following code should run on the microcontroller board circuit shown in Figure 4.4 and Figure 4.5:
int photoresistorPin = PB1; int photoresistorReading; void setup(void) { pinMode(PB12, OUTPUT); pinMode(PB14, OUTPUT); pinMode(PB15, OUTPUT); } void loop(void) { photoresistorReading = analogRead(photoresistorPin); digitalWrite(PB12, LOW); digitalWrite(PB14, LOW); digitalWrite(PB15, LOW); if (photoresistorReading < 600) { digitalWrite(PB15, HIGH); } else if (photoresistorReading < 1000) { digitalWrite...