-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLesson-5.ino
52 lines (35 loc) · 1.38 KB
/
Lesson-5.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**************************************
Lesson 5: Using Conditionals: Use knob range as a conditional
**************************************/
int ledPin = LED_BUILTIN; // same as pin 13
int knobPin = A0; // analog pin because range of numbers
int knobValue = 0; // variable for reading the knob
void setup() {
// put your setup code here, which runs once
// set digital pin as output
pinMode(ledPin, OUTPUT);
// start serial communications at 9600 baud
Serial.begin(9600);
}
void loop() {
// main program goes here
knobValue = analogRead(knobPin); // read the value of the knob and set it as <knobValue>
if (knobValue < 300) {
// knobValue is less than 300
knobValue = analogRead(knobPin);
digitalWrite(ledPin, HIGH); // turn the ledPin on
Serial.print("On, Knob=");
Serial.println(knobValue);
delay(knobValue); // stop the program for <knobValue> ms
knobValue = analogRead(knobPin);
digitalWrite(ledPin, LOW); // turn the ledPin off
Serial.print("Off, Knob=");
Serial.println(knobValue);
delay(knobValue); // stop the program for <knobValue> ms
} else {
//knobValue is 300 or greater
digitalWrite(ledPin, HIGH); // turn the ledPin on
Serial.print("On, Knob=");
Serial.println(knobValue);
} // end of knobValue if/else
}