-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.txt
More file actions
78 lines (64 loc) · 2.06 KB
/
Copy pathcode.txt
File metadata and controls
78 lines (64 loc) · 2.06 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// © 2021 Noora - All Rights Reserved
// Originally Developed: November 27, 2021
// Uploaded to GitHub: 2024
// This code is part of the Arduino Ventilator System
#include <LCD_I2C.h>
LCD_I2C lcd(0x27); // Default address of most PCF8574 modules, change according
#include <VarSpeedServo.h>
VarSpeedServo servo1, servo2;
int pot = A3;
int button1 = 7;
int button2 = 6;
int Speed = 0;
int Angle = 75;
int AnglePos = 0;
int pos = 0;
bool stp = true;
const byte interruptPin = 2;
void setup(){
Serial.begin(9600);
lcd.begin();
lcd.backlight();
pinMode(pot, INPUT);
pinMode (button1, INPUT_PULLUP);
pinMode (button2, INPUT_PULLUP);
servo1.attach(9);
servo1.write(0);
servo2.attach(10);
servo2.write(0);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin),StpStrt, FALLING);
}
void loop(){
int potVal = analogRead(pot);
//Serial.println(potVal);
lcd.setCursor (0,0);
lcd.print("Pot: ");
lcd.setCursor(5, 0);
lcd.print(potVal);
if (potVal < 1000){ lcd.setCursor(8,0); lcd.print(" ");}
if (potVal < 100){ lcd.setCursor(7,0); lcd.print(" ");}
if (potVal < 10){ lcd.setCursor(6,0); lcd.print(" ");}
Speed = map(potVal, 0, 1023, 10, 255);
lcd.setCursor (10,0); lcd.print("Sp:");
lcd.setCursor (13,0); lcd.print(Speed);
if (Speed < 100){ lcd.setCursor (15,0); lcd.print(" ");}
if (Speed < 10){ lcd.setCursor (14,0); lcd.print(" ");}
if (digitalRead(button1) == LOW){ if (Angle != 150) {Angle++; delay(150);}}
if (digitalRead(button2) == LOW) {if (Angle != 0) {Angle--; delay(150);}}
lcd.setCursor (0,1); lcd.print ("Angle: ");
lcd.setCursor (7,1); lcd.print (Angle);
if (Angle < 100){ lcd.setCursor (9,1); lcd.print(" ");}
if (Angle < 10){ lcd.setCursor (8,1); lcd.print(" ");}
Serial.println (Speed);
if (stp == false){
servo1.stop();
}
if (stp == true){
servo1.write(Angle,Speed,true);
servo1.write(0,Speed,true);}
}
void StpStrt(){
stp = !stp;
delay (1000);
}