Arduino Shock Watch
Arduino Shock Watch
ALARM***
***WRIST WATCH***
REQUIRED MATERIALS:-
PIECES PRICE
CIRCUIT DIAGRAMS :-
.
FUNCTIONS OF WATCH :-
// Editing mode
Bool editHH;
Bool editMM;
Bool editAmPm;
Bool settingsMode;
Bool alarmMode;
Bool shockMode;
Bool editShockP;
Bool editShockT;
Bool oledOn = true;
Float batteryVoltage;
Float ledVoltage;
// Button Pins
Button DecreaseBtn(5);
Button ModeBtn(6);
Button IncreaseBtn(7);
#define buzzerPin 11
#define shockPin 10
// Battery bitmaps
// Battery charging
Const unsigned char BatteryCharging [] PROGMEM = {
0x7f, 0xff, 0xf8, 0x80, 0x00, 0x06, 0x80, 0x00, 0x02, 0x80, 0x00,
0x06, 0x80, 0x30, 0x03, 0x86,
0x3c, 0x03, 0x83, 0xff, 0x03, 0x80, 0xff, 0x83, 0x80, 0x30, 0x03,
0x80, 0x00, 0x06, 0x80, 0x00,
0x02, 0x80, 0x00, 0x06, 0x7f, 0xff, 0xfc
};
Serial.begin(115200);
// SSD1306_SWITCHCAPVCC = generate display voltage from
3.3V internally
If (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address
0x3C for 128x32
Serial.println(F(“SSD1306 allocation failed”));
For (;;); // Don’t proceed, loop forever
}
DecreaseBtn.begin();
ModeBtn.begin();
IncreaseBtn.begin();
// alaram function
Void setAlaram() {
If (Al_minute > 60) {
Al_minute = 59;
}
If (Al_minute > 59) {
Al_minute = 0;
If (Al_hour < 1) {
Hour = 12;
}
Display.clearDisplay();
Display.setTextSize(2);
Display.setTextColor(WHITE);
Display.setCursor(10, 0);
Display.println(Al_time);
Display.setTextSize(1);
Display.setCursor(25, 20);
Display.println(“Set Alaram”);
If (editHH) {
Display.setCursor(10, 10);
} else if (editMM) {
Display.setCursor(50, 10);
}
Else if (editAmPm) {
Display.setCursor(80, 10);
}
Display.println(“__”);
Display.display();
Void openSettings() {
Display.setTextSize(1);
Display.setCursor(35, 20);
Display.println(“Set Time”);
}
Void showTime() {
If (minute > 60) {
Minute = 59;
}
If (minute > 59) {
Minute = 0;
If (hour < 1) {
Hour = 12;
}
Display.clearDisplay();
Display.setTextSize(2);
Display.setTextColor(WHITE);
If (hour < 10) {
Display.setCursor(5, 0);
} else {
Display.setCursor(0, 0);
}
Display.println(time);
Display.setCursor(100, 0);
Display.println(AMorPM);
If (settingsMode) {
openSettings();
}
If (settingsMode) {
If (editHH) {
Display.setCursor(1, 10);
} else if (editMM) {
Display.setCursor(40, 10);
}
Else if (editAmPm) {
Display.setCursor(100, 10);
}
Display.println(“__”);
}
If (!settingsMode) {
If (ledVoltage > 3.5) {
Display.drawBitmap(5, 19, BatteryCharging, 24, 13, WHITE);
}
Else if (batteryVoltage > 4) {
Display.drawBitmap(5, 19, BatteryFull, 24, 13, WHITE);
} else if (batteryVoltage < 3.7) {
Display.drawBitmap(5, 19, BatteryDown, 24, 13, WHITE);
}
}
Display.display();
}
Void increaseTime() {
// Store the currentMillis
Unsigned long TcurrentMillis = millis();
If (editShockT) {
If (DecreaseBtn.wasPressed()) {
shockTime -= 10;
}
If (IncreaseBtn.wasPressed()) {
shockTime += 10;
}
}
Display.clearDisplay();
Display.setTextSize(2);
Display.setTextColor(WHITE);
Display.setCursor(0, 0);
Display.println(shockTimeStr);
Display.display();
}
increaseTime();
// calling increaseTime every time
If (DecreaseBtn.wasPressed()) {
Hour--;
}
If (IncreaseBtn.wasPressed()) {
Hour++;
}
}
Else if (editMM) {
If (DecreaseBtn.wasPressed()) {
Minute--;
}
If (IncreaseBtn.wasPressed()) {
Minute++;
}
}
Else if (editAmPm) {
If (DecreaseBtn.wasPressed()) {
If (AMorPM == “PM”) {
AMorPM = “AM”;
} else if (AMorPM = “AM”) {
AMorPM = “PM”;
}
}
If (IncreaseBtn.wasPressed()) {
If (AMorPM == “PM”) {
AMorPM = “AM”;
} else if (AMorPM = “AM”) {
AMorPM = “PM”;
}
}
}
If (alarmMode) {
If (editHH) {
If (DecreaseBtn.wasPressed()) {
Al_hour--;
}
If (IncreaseBtn.wasPressed()) {
Al_hour++;
}
}
Else if (editMM) {
If (DecreaseBtn.wasPressed()) {
Al_minute--;
}
If (IncreaseBtn.wasPressed()) {
Al_minute++;
}
} else if (editAmPm) {
If (DecreaseBtn.wasPressed()) {
If (Al_AMorPM == “PM”) {
Al_AMorPM = “AM”;
} else if (Al_AMorPM = “AM”) {
Al_AMorPM = “PM”;
}
}
If (IncreaseBtn.wasPressed()) {
If (Al_AMorPM == “PM”) {
Al_AMorPM = “AM”;
} else if (Al_AMorPM == “AM”) {
Al_AMorPM = “PM”;
}
}
}
}
}
}
If ( ModeBtn.wasPressed() || IncreaseBtn.wasPressed() ||
DecreaseBtn.wasPressed() && !oledOn) {
oledOn = true;
DpreviousMillis = DcurrentMillis;
}
If (alarmMode) {
Switch (modeBtnCount) {
Case 1:
editHH = true;
break;
case 2:
editHH = false;
editMM = true;
break;
case 3:
editMM = false;
editAmPm = true;
break;
case 4:
editAmPm = false;
settingsMode = false;
alarmMode = false;
shockMode = true;
modeBtnCount = 0;
}
setAlaram();
}
If (ModeBtn.wasPressed() && shockMode) {
modeBtnCount++;
If (shockMode) {
Switch (modeBtnCount) {
Case 1:
editShockT = true;
break;
case 2:
editShockT = false;
shockMode = false;
modeBtnCount = 1;
break;
}
}
If (shockMode) {
shockSettings();
}
}
// give shock every sec after 10 sec of alaram beeping
If (Al_hour == hour && Al_minute == minute && second <
shockTime + 10 && second > 10 && second % 2 == 0) {
digitalWrite(shockPin, HIGH);
} else {
digitalWrite(shockPin, LOW);
delay(50);