-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino-singing-bowl.ino
67 lines (53 loc) · 1.61 KB
/
arduino-singing-bowl.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <Servo.h>
Servo servo1;
const int buttonPin = 3;
const int servoPin = 9;
const int debounceDelay = 50;
int on;
int buttonReading;
int lastSteadyState = LOW;
int lastFlickerableState = LOW;
long timeInBetweenButtonPresses;
unsigned long lastDebounceTime = 0;
void setup() {
Serial.begin(9600);
Serial.println("setting things up...");
pinMode(buttonPin, INPUT);
servo1.attach(servoPin);
on = false;
}
void loop() {
buttonReading = digitalRead(buttonPin);
if (buttonReading != lastFlickerableState) {
Serial.println("lastFlicerableState: " + String(lastFlickerableState));
Serial.println("buttonReading: " + String(buttonReading));
Serial.println("flickering...");
lastDebounceTime = millis();
lastFlickerableState = buttonReading;
}
if ((millis() - lastDebounceTime) > debounceDelay) {
Serial.println("millis: " + String(millis()));
Serial.println("lastDebounce: " + String(lastDebounceTime));
Serial.println("debounceDelay: " + String(debounceDelay));
if (lastSteadyState == HIGH && buttonReading == LOW) {
Serial.println("The button is pressed");
on = !on;
}
else if (lastSteadyState == LOW && buttonReading == HIGH) {
Serial.println("The button is released");
}
lastSteadyState = buttonReading;
}
if (on) {
startStriker();
}
servo1.write(0);
}
void startStriker() {
int position = 75;
int timeInBetween = 4000;
servo1.write(position); // Tell servo to go to 180 degrees
delay(400); // Pause to get it time to move
servo1.write(0); // Tell servo to go to 0 degrees
delay(timeInBetween);
}