-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtamagotuino.ino
159 lines (137 loc) · 2.96 KB
/
tamagotuino.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int feedButton = 6;
const int heatSensor = A0;
const int temperatureThreshold = 23.0;
int fullness = 10;
float rawTemperature;
int temperature;
int pitch = 1000;
int cryCounter = 0;
bool isHungry;
bool isCold;
bool isDead;
bool soundOn = false;
int activatedFeedButton = 0;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(feedButton, INPUT);
for (int ledNumber = 8; ledNumber < 11; ledNumber++) {
pinMode(ledNumber, OUTPUT);
digitalWrite(ledNumber, LOW);
}
checkTemperature();
contentDisplay();
}
void loop() {
activatedFeedButton = digitalRead(feedButton);
int heatValue = analogRead(heatSensor);
float voltage = (heatValue/1024.0) * 5;
rawTemperature = (voltage -.5) * 100;
temperature = (int) rawTemperature;
checkTemperature();
if (isDead == false) ledStatus();
if (fullness <= 0 || temperature < (temperatureThreshold - 5)) {
if (cryCounter == 0 && soundOn == true) {
deathCry();
cryCounter++;
}
diedDisplay();
} else if (fullness < 6) {
gettingHungryDisplay();
isHungry = true;
if (soundOn == true) {
gettingHungrySound();
}
live();
} else if (isCold == true) {
gettingColdDisplay();
live();
} else {
contentDisplay();
live();
}
if (activatedFeedButton == HIGH && isHungry == true) {
feed();
}
}
void live() {
delay(500);
fullness--;
}
void feed() {
isHungry = false;
fullness = 10;
}
void checkTemperature() {
if (temperature < temperatureThreshold) {
isCold = true;
} else {
isCold = false;
}
}
void ledStatus() {
Serial.print("THIS IS BEING CALLED");
if (temperature >= temperatureThreshold) {
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
} else if (temperature <= (temperatureThreshold - 5)) {
isDead = true;
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
} else if (temperature < (temperatureThreshold - 3)) {
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
} else {
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
}
void gettingHungrySound() {
tone(7, 100, 150);
delay(150);
tone(7, 150, 75);
delay(75);
tone(7, 160, 75);
}
void deathCry() {
tone(7, 80, 150);
delay(150);
tone(7, 70, 150);
delay(150);
tone(7, 60, 450);
}
void contentDisplay() {
lcd.clear();
lcd.print("Pet is content");
lcd.setCursor(0, 1);
lcd.print("(^_^)");
}
void gettingHungryDisplay() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Getting hungry");
lcd.setCursor(0, 1);
lcd.print("(o_o)");
}
void gettingColdDisplay() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Getting cold");
lcd.setCursor(0, 1);
lcd.print("(~_~)");
delay(1000);
}
void diedDisplay() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("You messed up...");
lcd.setCursor(0, 1);
lcd.print("(X_X)");
delay(10000);
}