-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWKey.ino
33 lines (27 loc) · 806 Bytes
/
CWKey.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
const int VRy = A0; // select the input pin for the potentiometer
const int buzzerPin = 9; // select the pin for the buzzer
const int pause = 100; // change length of pause; dot = 1 pause and dash = 3 dots
const int mid = 1024 / 2; // when joystick is in the middle in the ideal world
const int err = 10; // used for determining threshold
int yPosition = 0;
int beep = 0;
void setup() {
pinMode(VRy, INPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
while(1){
yPosition = analogRead(VRy);
if(yPosition > mid + err) {
beep = pause * 3;
} else if (yPosition < mid - err) {
beep = pause;
} else {
break;
}
digitalWrite(buzzerPin, HIGH);
delay(beep);
digitalWrite(buzzerPin, LOW);
delay(pause);
}
}