Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.