Created
March 11, 2018 06:33
-
-
Save griv/93301fc1da77736804dc98ce0402512b to your computer and use it in GitHub Desktop.
Test phototransistor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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