1
2
3#include <Arduino.h>
4#include <U8g2lib.h>
5
6
7
8U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, 13, 11, 10, 8);
9byte inPin1 = 5;
10byte outPin1 = 7;
11byte time_healing = 7;
12char time_healing_str[3];
13byte time_healing1;
14byte time_pause = 20;
15byte time_pause1;
16char time_pause_str[3];
17byte cycle = 4;
18char cycle_str[3];
19byte interruptPin = 2;
20byte ZapperPin = 4;
21char* message;
22
23void setup() {
24 u8g2.begin();
25 pinMode(inPin1, INPUT_PULLUP);
26 pinMode(outPin1, OUTPUT);
27 pinMode(13, OUTPUT);
28 digitalWrite (13, LOW);
29 pinMode(8, OUTPUT);
30 digitalWrite (8, LOW);
31 pinMode(ZapperPin, OUTPUT);
32 digitalWrite (ZapperPin, LOW);
33 Serial.begin(9600);
34}
35
36void loop() {
37
38 cycle = 0;
39 digitalWrite(inPin1, HIGH);
40 do {
41 message = " PRESS START";
42 DisplayLCD();
43 } while (digitalRead(inPin1) == HIGH);
44
45 cycle = 3; beep(); Work();
46 beep(); Pause();
47 cycle = 2; beep(); Work();
48 beep(); Pause();
49 cycle = 1; beep(); Work();
50 beep(); delay(50); beep(); delay(50); beep();
51 time_healing1 = 0; time_pause1 = 0;
52}
53
54void Work() {
55 time_healing1 = time_healing + 1;
56 message = "HEALING";
57 for (byte j = 1; j <= time_healing; j++) {
58 time_healing1--;
59 strcpy(time_healing_str, u8x8_u8toa(time_healing1, 2));
60 DisplayLCD();
61 Generate_30kHz();
62 }
63 time_healing1 = 0;
64}
65
66void Pause() {
67 time_pause1 = time_pause + 1;
68 message = "PAUSE";
69 byte s, m, th;
70 for (th = 0; th < time_pause; th++) {
71 time_pause1--;
72 strcpy(time_pause_str, u8x8_u8toa(time_pause1, 2));
73 DisplayLCD();
74 for (s = 0; s < 60; s++) {
75 delay (1000);
76 }
77 }
78 time_pause1 = 0;
79}
80
81void Generate_30kHz() {
82 for (byte z = 1; z < 60; z++ ) {
83 for (int i = 1; i < 30000; i++) {
84 for (byte j = 1; j < 67; j++) {
85 PORTD = B00010000;
86 }
87
88 for (byte j = 1; j<66; j++) {
89 PORTD = B00000000;
90 }
91 }
92 }
93}
94
95void beep() {
96 digitalWrite(outPin1, HIGH);
97 delay(100);
98 digitalWrite(outPin1, LOW);
99}
100
101void DisplayLCD(){
102 strcpy(cycle_str, u8x8_u8toa(cycle, 1));
103 u8g2.setFont(u8g2_font_6x12_tr);
104 u8g2.firstPage();
105 do {
106 u8g2.drawBox(0, 0, 128, 10);
107 u8g2.setDrawColor(2);
108 u8g2.setFontMode(1);
109 u8g2.drawFrame(0,11,128,53);
110 u8g2.drawRFrame(2,13,124,49,10);
111 u8g2.drawStr(40, 8, " ZAPPER");
112 u8g2.setDrawColor(1);
113 u8g2.setFontMode(1);
114 if (cycle == 0) {u8g2.drawStr(20, 40, message);}
115 if (cycle > 0) {
116
117 u8g2.setFont(u8g2_font_6x12_tr);
118 u8g2.drawStr(15, 50, message);
119 u8g2.drawStr(95, 50, "min.");
120 u8g2.setFont(u8g2_font_9x18_tn);
121 if (time_pause1 > 0 ) { u8g2.drawStr(70, 50, time_pause_str);}
122 if (time_healing1 > 0 ) {u8g2.drawStr(70, 50, time_healing_str);}
123 u8g2.drawStr(55, 30, cycle_str);
124 }
125 } while ( u8g2.nextPage() );
126}