Skip to content

Latest commit

 

History

History
executable file
·
26 lines (20 loc) · 481 Bytes

06_photoresistor.md

File metadata and controls

executable file
·
26 lines (20 loc) · 481 Bytes

06. Photoresistor

/*  06. Photoresistor
        https://tinyurl.com/yerrf5nd
*/
#define LED  9

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int light = analogRead(A0);                   // 10-bit
  int level = map(light, 0, 1023, 0, 255);      // map 0--1023 to 0--255

  Serial.print(light);
  Serial.print(", ");
  Serial.println(level);

  analogWrite(LED, level);                      // 8-bit
}