-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharc497.particlePhoton.servoMotor
72 lines (51 loc) · 1.24 KB
/
arc497.particlePhoton.servoMotor
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
/*these first lines aren't exactly variables
*/
#define SWITCH_PIN 1
#define LED_PIN 2
Timer bounceTimer(10, bounceFunction, 1);
bool switchState = 0;
bool switchValue = 0;
bool direction = 1;
int fadeCounter = 0;
void setup() {
pinMode(SWITCH_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
switchValue = digitalRead(SWITCH_PIN);
if (switchValue==0){
bounceTimer.start();
while(bounceTimer.isActive()){
//do nothing
}
//digitalWrite(LED_PIN, HIGH);
//Particle.publish("button", 0);
}
if(switchState == 1){
fade();
}
else {
digitalWrite(LED_PIN, LOW);
//Particle.publish("button", 1);
}
}
void bounceFunction(){
switchState = !switchState;
Particle.publish("Button", String(switchState));
}
void fade(){
if(direction==1){
fadeCounter++;
}
else{
fadeCounter--;
}
if(fadeCounter >= 255){
direction = 0;
}
if(fadeCounter <=0){
direction = 1;
}
analogWrite(LED_PIN, fadeCounter);
delay(10);
}