-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUselessBox.ino
More file actions
101 lines (84 loc) · 1.69 KB
/
Copy pathUselessBox.ino
File metadata and controls
101 lines (84 loc) · 1.69 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <EEPROM.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include <Servo.h>
Adafruit_7segment matrix = Adafruit_7segment();
const int switchPin = 10; //active low
const int servoLidPin = 8;
const int servoFingerPin = 5;
Servo servoLid;
int closedPos = 175;
int openPos = 70;
bool boxOpen = false;
Servo servoFinger;
int fingerOutPos = 168;
int fingerInPos = 85;
bool fingerExtended = false;
bool lastRead = false;
int usage = 0;
void setBoxLid(bool isBoxOpen) {
boxOpen = isBoxOpen;
if (boxOpen)
servoLid.write(openPos);
else
servoLid.write(closedPos);
}
void setFingerExtended(bool isExtended){
fingerExtended = isExtended;
if(fingerExtended)
servoFinger.write(fingerOutPos);
else
servoFinger.write(fingerInPos);
}
bool buttonPressed() {
if(digitalRead(switchPin) != lastRead)
{
if(lastRead == true)
{
lastRead = false;
return true;
}
else
{
lastRead = true;
}
}
return false;
}
void setup() {
matrix.begin(0x70);
//Serial.begin(9600);
pinMode(switchPin, INPUT_PULLUP);
servoLid.attach(servoLidPin);
servoFinger.attach(servoFingerPin);
EEPROM.get(0, usage);
if(usage < 0){
usage = 0;
}
matrix.println(usage);
matrix.writeDisplay();
setFingerExtended(false);
delay(500);
setBoxLid(false);
}
void loop() {
if(buttonPressed()){
EEPROM.put(0, usage);
matrix.println(usage);
matrix.writeDisplay();
}
if(digitalRead(switchPin) == LOW){
setBoxLid(false);
delay(700);
}
else{
setBoxLid(true);
delay(700);
setFingerExtended(true);
delay(320);
setFingerExtended(false);
usage++;
}
delay(100);
}