If you want to follow along at home, you can order the Arduino Kit we are using HERE. The nice digital voltmeter used in the lesson is available HERE.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
int lightPin=A0; int buzzPin=8; int lightVal; int delayT; void setup() { // put your setup code here, to run once: pinMode(A0, INPUT); pinMode(buzzPin,OUTPUT); Serial.begin(9600); } void loop() { lightVal=analogRead(lightPin); delayT=(9./550.)*lightVal-(9.*200./550.)+1.; Serial.println(delayT); digitalWrite(buzzPin, HIGH); delay(delayT); digitalWrite(buzzPin, LOW); delay(delayT); } |