-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspark-gong.ino
87 lines (77 loc) · 2.64 KB
/
spark-gong.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* SPARK SERVO GONG
* =========================================================
* Copy this into a new application at:
* https://www.spark.io/build and go nuts!
* ---------------------------------------------------------
* Based on: https://github.com/technobly/SparkCore-FacebookLikesAlert
* =========================================================
*
*
* WIRING is so simple
* -----------------------------
* SERVO SPARK CORE
* Brown or Black - GND
* Red - VIN (5V)
* Orange or White - A7
* -----------------------------
*/
/* ============================= INCLUDES ================================== */
#include "application.h"
/* === CHANGE THESE NUMBERS TO FIND WHAT SERVO DEGREE MAPS TO WHICH DIGIT == */
#define SERVO_DEG_0 0 // servo degree value to point to digit 0
#define SERVO_DEG_9 180 // servo degree value to point to digit 9
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
// Define the pins we're going to call pinMode on
int led = D0; // You'll need to wire an LED to this one to see it blink.
int led2 = D7; // This one is the built-in tiny one to the right of the USB jack
float resting = 28;
float angServo = resting;
float angGoal = angServo;
bool reset = false;
/* This function is called once at start up ---------------------------------*/
void setup(){
Spark.function("pushed", pushed);
myservo.attach(A7); // attaches servo to A7 pin to the servo object
myservo.write(angGoal);
gong();
}
void gong(){
angGoal = 160;
reset = true;
}
void pushed(String foo){
// Not using the 'foo' string param currently, but could
// be used to change behavior based on branch, author etc.
gong();
digitalWrite(led, HIGH); // Turn ON the LED pins
digitalWrite(led2, HIGH);
delay(5000); // Wait for 5000mS = 5 seconds
digitalWrite(led, LOW); // Turn OFF the LED pins
digitalWrite(led2, LOW);
}
/* This function loops forever ----------------------------------------------*/
void loop(){
if(angServo != angGoal){
if(angGoal > angServo){
if(angServo > 90){
angServo += .125; // gently engage bell clapper lever
}else{
angServo += .25;
}
}else{
if(angServo > 70){
angServo -= 1;
}else{
angServo -= .125; // return to resting position gently
}
}
myservo.write(angServo);
if(angServo == angGoal && reset){
delay(5000);
reset = false;
angGoal = resting;
}
}
}