-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerial Coms.ino
More file actions
61 lines (51 loc) · 1.25 KB
/
Copy pathSerial Coms.ino
File metadata and controls
61 lines (51 loc) · 1.25 KB
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
53
54
55
56
57
58
59
60
61
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Enter a number:");
}
void loop() {
if (Serial.available()) {
int num = Serial.parseInt();
Serial.println(num);
if (num % 2 == 0) {
Serial.println("Number is Even");
blinkLED(3); // Now 3 times for even
} else {
Serial.println("Number is Odd");
blinkLED(2); // Now 2 times for odd
}
}
}
void blinkLED(int times) {
for (int i = 0; i < times; i++) {
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
delay(300);
}
}
--------------------------------------------------------------------------
#include <Servo.h>
int servoPin = 3;
Servo servo;
int num = 0; // Declare num globally
void setup() {
servo.attach(servoPin);
Serial.begin(9600);
Serial.println("Enter a number:");
}
void loop() {
if (Serial.available()) {
num = Serial.parseInt(); // Update the global variable
Serial.print("You Entered: ");
Serial.println(num);
if (num < 40) {
servo.write(90);
} else {
servo.write(180);
}
delay(500); // Give time for servo to move
Serial.println("Enter another number:");
}
}