Skip to content

Instantly share code, notes, and snippets.

@griv
Created March 11, 2018 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save griv/93301fc1da77736804dc98ce0402512b to your computer and use it in GitHub Desktop.
Save griv/93301fc1da77736804dc98ce0402512b to your computer and use it in GitHub Desktop.
Test phototransistor
// phototransistor test
int pt = A0;
int led = 11;
int val = 0;
void setup() {
// analog in
pinMode(pt, INPUT);
// pwm out
pinMode(led, OUTPUT);
// begin serial
Serial.begin(9600);
}
void loop() {
// read from analog pin
val = analogRead(pt);
// print to serial
Serial.println(val);
// fade led in sync with analog read (map to pwm range)
analogWrite(led, map(val, 0, 1023, 0, 255));
// 10 fps
delay(1000/10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment