forked from shinkrillin/Train-Controller-Touch-Control
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSketch
More file actions
76 lines (57 loc) · 1.28 KB
/
Sketch
File metadata and controls
76 lines (57 loc) · 1.28 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
#include <CapacitiveSensor.h>
long time = 0;
int state = HIGH;
boolean yes;
boolean previous = false;
int debounce = 200;
CapacitiveSensor cs_6_4 = CapacitiveSensor(6,4);
// 10 MegOhm resistor between 6 and 4, 4 is the sensor.
void setup()
{
//Set pin assignments
pinMode(2, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, INPUT);
Serial.begin(9600);
}
void loop()
{
long totall = cs_6_4.capacitiveSensor(30);
if (totall > 60){yes = true;}
else {yes = false;}
if(yes == true && previous == false &&millis() - time>debounce)
{
//Ring the Bell!
digitalWrite(2, HIGH);
delay (300);
digitalWrite(2, LOW);
delay (400);
digitalWrite(2, HIGH);
delay (300);
digitalWrite(2, LOW);
delay (400);
digitalWrite(2, HIGH);
delay (300);
digitalWrite(2, LOW);
//Press and hold accelerate button.
digitalWrite(3, HIGH);
delay (5000);
digitalWrite(3, LOW);
//Wait for the train to roll for a bit.
delay (35000);
//Press and hold the decelerate button.
digitalWrite(4, HIGH);
delay (7000);
digitalWrite(4, LOW);
//Ring the bell again!!
digitalWrite(2, HIGH);
delay(300);
digitalWrite(2, LOW);
delay(400);
digitalWrite(2, HIGH);
delay(300);
digitalWrite(2, LOW);
delay(500);
}
}